1 Replies - 708 Views - Last Post: 07 October 2015 - 07:02 AM

#1 strident.silence   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 18-November 13

Razor dropdown with nested object list

Posted 06 October 2015 - 12:25 PM

Ok I have an edit page with several dropdowns that are working correctly

@Html.DropDownListFor(model => model.Form.RequestType, new SelectList(Model.Form.RequestTypes, "Value", "Text"), "defaultValue")



This is working correctly, when I pass the view model to the view, the request type is selected by default.

However, I have an issue with nested fields, for example: model.Form.Financelist[0].TaxCode, selects the SelectList default value.

@Html.DropDownListFor(model => model.Form.FinanceList[0].TaxCode, new SelectList(Model.Form.TaxCodes, "Value", "Text"), "defaultValue")



The dropdown is populated with the TaxCodes, but it seems like the expression does not return the value. When I check in Model.Form.FinanceList[0].TaxCode the field has the expected value (matching the "Value" of the SelectList).

Why is this not working? Thank you.

Oh, I also tried with
model => model.Form.FinanceList.ElementAt(0).TaxCode

And it still does not work.

Is This A Good Question/Topic? 0
  • +

Replies To: Razor dropdown with nested object list

#2 strident.silence   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 18-November 13

Re: Razor dropdown with nested object list

Posted 07 October 2015 - 07:02 AM

eidt: Ok so I created a partial view using the Financial object as the model. I iterate over financials and render the partial for each instance, it work. I am still not sure why it did not work the way I tried before.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1