Dear Frnds,
I am developing Purchase order screen in mvc.. I have two models 'MRHdr' and 'MRDtl' How to use two models in single view. I am trying 3 days please help me...
Eg. Textbox values save in 'MRHdr' and grid values save in 'MRDtl'
What I have tried:
Models: public class MRHdr
{
[Key]
public int Id { get; set; }
public string MRNo { get; set; }
public DateTime MRDate { get; set; }
public string Remarks { get; set; }
}
public class MRDtl
{
[Key]
public int Id { get; set; }
public string MRNo { get; set; }
public string IRateCode { get; set; }
public string ItemCode { get; set; }
public int QtyRequested { get; set; }
}
View Model:
public class VwModel
{
public MRHdr MRHdr { get; set; }
public MRDtl MRDtl { get; set; }
}
Controller:
public ActionResult Create()
{
MRHdr objMRHdr = new MRHdr() { MRNo = "", MRDate = DateTime.Now };
MRDtl objMRDtl = new MRDtl() { IRateCode = "", ItemCode = "", QtyRequested = 0 };
List model = new List();
model.Add(new VwModel { MRHdr = objMRHdr, MRDtl = objMRDtl });
return View(model);
}
View:
@model Telecom.ViewModel.VwModel
@using (Html.BeginForm("Create", "MatReq", FormMethod.Post))
{
@{Html.RenderPartial("_MRHdrs",Model.MRHdr);}
@{Html.RenderPartial("_MRDtls", Model.MRDtl);}
}
Partial View:1
@model List< Telecom.Models.MRDtl >
Partial View:2
@model Telecom.Models.MRHdr