Click here to Skip to main content
16,004,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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" />;

}
Posted
Updated 20-Jul-16 22:54pm
v2

1 solution

Your model defines MRHdr

C#
public MRHdr MRHdr { get; set; }


but your code uses MRSHdr

@Html.TextBoxFor(model => model.MRSHdr.MRNo)


Change the TextBoxFor to use MRHdr, or change the property in the model to be MRSHdr, but the two have to match.
 
Share this answer
 
Comments
Vivek.anand34 21-Jul-16 5:24am    
Thank U.. But another error comes now. CS1501: No overload for method 'Write' takes 0 arguments
@{Html.RenderPartial("_MRDtls");}
F-ES Sitecore 21-Jul-16 5:30am    
There will be a syntax issue in the _MRDtls partial view, looking for any code in it that uses "Write"
F-ES Sitecore 21-Jul-16 6:04am    
If your view takes a list of things you can't use model.MRHdr as "model" is an IEnumerable of your class, it isn't a single class with properties. How you handle this depends on your business requirements, if your partial show expects multiple items or just a single item.

You should create new questions for new issues rather than adding to your existing one.
Vivek.anand34 21-Jul-16 6:14am    
I don't know how to use multiple modal in single view.. for eg.. I need to save Text box value and Grid values are two different tables... can you send any links.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900