ورود

View Full Version : نمایش عناصر دو مدل ترکیبی



نیکناز
سه شنبه 29 مرداد 1392, 08:04 صبح
سلام .
من می خوام دو تا مدل و تحت یک مدل به یه ویو بفرستم .
که این کار رو کردم .






publicclassViewModelX

{



public tbl_sefaresh tbl_sefaresh{ get; set; }

public tbl_sabad_kharid tbl_sabad_kharid{ get; set; }
}





کنترلر :




[HttpGet]

publicActionResultncheckout(string nameKarbar)

{

ViewBag.username = nameKarbar;



var FeacherToTwoModel = newViewModelX() ;



returnView(FeacherToTwoModel);



}





[HttpPost]

publicActionResultncheckout(ViewModelX model)

{





if (ModelState.IsValid)

{



UsersClass.InsertInSefareshAndSabad(model.tbl_sefa resh.id,model.tbl_sefaresh.id_noe_pardakht,model.t bl_sefaresh.username,model.tbl_sabad_kharid.userna me,model.tbl_sabad_kharid.id_sefaresh);

}

else

{



}

return View();



}






ویو :








.




.




.




<div id="collapseFour"class="accordion-bodycollapse">




<div class="accordion-inner">




@modelMyProject.Models.ViewModelX




<p>please select a style</p>




<label class="checkboxpayment-method inline">






@Html.CheckBoxFor(m => m. )remember me </label>




<label class="checkboxpayment-method inline">




@Html.CheckBoxFor(m => m. )




online




</label>




<form class="form-inline">




<input class="input-block span4"placeholder="Enter your coupon codehere" type="text" id="couponcode">




<button type="submit"class="btn btn-general">register</button>




</form>




</div>




</div>




.




.




.






<tbody>




@modelIEnumerable<MyProject.Models.vw_basket>




@foreach (var item inModel)




{




<tr>




<td class="image"><ahref='../Kala/Product?NID=@item.id_kala'>




<img'@item.comment'alt='@item.name_product' src="~/Content/Media/Images/product/@MyProject.Models.ProductClass.GetPicById_Product( int.Parse(item.id_Product.ToString()))" width="100"></a></td>




<td class="product"><ahref='../Kala/Product?NID=@item.id_ Product ' title='@item.comment'>@item.name_ Product </a> </td>




<td class="stock">@item.number</td>




<td class="price"><s></s><b>@item.cost</b></td>




<td class="price"><b>@(item.number*item.cost)</b></td>




</tr>




}




<tr>






</tr>




</tbody>




.




.







ولی چرا تو ویو فیلد ها رو نمی شناسه .
مثلا این :


@Html.CheckBoxFor(m => m.)

ali_autumnal
سه شنبه 29 مرداد 1392, 16:37 عصر
@modelIEnumerable<MyProject.Models.vw_basket>


این درست نیست.

شما باید اینطور بنویسید:


public class a
{
public int id{set;get;}
public string name{set;get;}
}

public class b
{
public int commentId{set;get;}
public string content{set;get;}
}


public class c
{
public IList<a> aModel{set;get;}
public IList<b> bModel{set;get;}
}


View Code:



@model c


@forech(var name in Model.aModel
{
...
}

@forech(var comment in Model.bModel
{
...
}