asp mvc partial with model and ViewDataDictionary - how do I access the ViewDataDictionary?

后端 未结 1 1644
借酒劲吻你
借酒劲吻你 2020-12-24 11:54

I am creating a form which updates two related models, for this example a Project with a collection of Tasks, I want the controller to accept a single Project which has its

相关标签:
1条回答
  • 2020-12-24 12:15

    Guess I posted too soon. This thread had the answer I was looking for

    asp.net MVC RC1 RenderPartial ViewDataDictionary

    I ended up using this terse syntax

    @Html.Partial("_TaskForm", Model.Tasks[i], new ViewDataDictionary { {"counter", i} } )
    

    Then in partial view

    @model MyWebApp.Models.Task
    @{
        int index = Convert.ToInt32(ViewData["counter"]);
    }
    
    <div>
        @Html.TextBox(String.Format("Tasks[{0}].Name", index), Model.Name)
    </div>
    <div>
        @Html.TextBox(String.Format("Tasks[{0}].DueDate", index), Model.DueDate)
    </div>
    
    0 讨论(0)
提交回复
热议问题