0

I have a model class. Inside that, I have a class and a list which is that type.

public class ItemSetupModel
{      
    public class UPC
    {
        public int ItemNumberForUPC { get; set; }
        public string GCOwner { get; set; }
        public string GCFeeItem { get; set; }
        public string GCBranded { get; set; }
        public string query { get; set; }
    }

    public List<UPC> lstUPC { get; set; }
    public UPC upc;

    public ItemSetupModel()
    {
        this.upc = new UPC();
        this.lstUPC = new List<UPC>();
        this.lstUPC.Add(this.upc);
    }
}

cshtml is as below :

@model PricingUpdates.Models.ItemSetupModel
@using (Html.BeginForm())
{
    @for (int i = 0; i < Model.lstUPC.Count; i++)
    {
        @Html.Label("ItemNumberForUPC", "ItemNumber")
        @Html.TextBoxFor(m => m.lstUPC[i].ItemNumberForUPC, new { @class = "form-control", Name = "UPCUpdate" + i })                 
    }
}

Whenever I am posting the values, the action result model will never contain the values entered by me in the textbox. It will always show null values for the list.

Abbas
  • 14,186
  • 6
  • 41
  • 72
  • 3
    Remove the `new { Name = "UPCUpdate" + i }` **NEVER** attempt to change the `name` attribute when using `HtmlHelper` methods –  Nov 22 '17 at 12:12
  • Removing new { Name = "UPCUpdate" + i } helped me..Yayyy thanks a lot. – Aiswarya Rajendran Nov 22 '17 at 12:20
  • Why does that make the difference i was not able to understand – Aiswarya Rajendran Nov 22 '17 at 12:20
  • 2
    Look at the html you generate before and after the change. Then read [this answer](http://stackoverflow.com/questions/30094047/html-table-to-ado-net-datatable/30094943#30094943) –  Nov 22 '17 at 12:22

0 Answers0