How to pass a nested model value in @Html.Partial

后端 未结 1 323
北荒
北荒 2021-01-21 06:02

I have a model as order inside it I have a another object which I am trying to use in @Html.Partial Code snippet

 public class Order{
   public string Id{set;get         


        
相关标签:
1条回答
  • 2021-01-21 06:32

    The reason for that is because the Partial is not respecting the naming convention for the input fields. Use an editor template instead:

    @model Order
    OrderId: 
    @Html.TextBoxFor(x => x.Id)
    
    ShippingAdress: 
    @Html.EditorFor(x => x.ShippingAdress)
    
    BillingAddress:
    @Html.EditorFor(x => x.BillingAdress)
    

    Now move your Adress.cshtml to ~/Views/Shared/EditorTemplates/Address.cshtml. The name and location of the template is important. It should be located in ~/Views/Shared/EditorTemplates and named the same way as the model type (Address.cshtml):

    @model Address
    ...
    
    0 讨论(0)
提交回复
热议问题