Dear Friends,
I have developed view modal in mvc: I have got an error
CS1061: 'Telecom.ViewModel.VwModel' does not contain a definition for 'MRSHdr' and no extension method 'MRSHdr' accepting a first argument of type 'Telecom.ViewModel.VwModel' could be found (are you missing a using directive or an assembly reference?)
Line 21: @Html.TextBoxFor(model => model.MRSHdr.MRNo)
Line 22: @Html.TextBoxFor(model => model.MRSHdr.MRDate)
What I have tried:
Modal:
[Table("MRHdr")]
public class MRHdr
{
[Key]
[Column(Order = 0)]
public int Id { get; set; }
public string MRNo { get; set; }
public DateTime MRDate { get; set; }
public string Remarks { get; set; }
public string GetUser { get; set; }
public string DelFlag { get; set; }
public DateTime? GetDate { get; set; }
public string CompCode { get; set; }
}
[Table("MRDtl")]
public class MRDtl
{
[Key]
[Column(Order = 0)]
public int Id { get; set; }
public string MRNo { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessage = "Item Name required!")]
public string IRateCode { get; set; }
public string ItemCode { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessage = "Quantity required!")]
public int QtyRequested { get; set; }
}
ViewModel:
public class VwModel
{
public MRHdr MRHdr { get; set; }
public MRDtl MRDtl { get; set; }
}
Controller:
public ActionResult Create()
{
return View();
}
PartialView:
@model IEnumerable< telecom. viewmodel. vwmodel>
@{
}
<style>
th {
text-align:left;
}
td {
padding:5px;
}
</style>
@using (Html.BeginForm("Create","MatReq", FormMethod.Post))
{
@if (Model != null && Model.Count > 0)
{
int j = 0;
foreach (var i in Model)
{
j++;
}
}
Item Name | Item Rate Code | Item Code | Qty Requested | |
@Html.TextBox("ItemName", null, new { id = "ItemName" }) | @Html.TextBoxFor(a=>a[j].IRateCode) | @Html.TextBoxFor(a=>a[j].ItemCode) | @Html.TextBoxFor(a=>a[j].QtyRequested) | @if (j > 0)
{
Remove
}
|
<input type="submit" value="Save" />;
}