Shorthand for creating a ViewDataDictionary with both a model and ViewData items?

前端 未结 5 1084
死守一世寂寞
死守一世寂寞 2020-12-13 09:43

Is there any way to create a ViewDataDictionary with a model and additional properties with a single line of code. I am trying to make a RenderPartial

5条回答
  •  孤街浪徒
    2020-12-13 10:15

    This is what worked for me in old style mvc aspx view:

    <% Html.RenderPartial("ContactPartial", Model.ContactFactuur, new ViewDataDictionary(this.ViewData ) { TemplateInfo = new TemplateInfo { HtmlFieldPrefix = "Factuur" } }); %>
    

    the thing here is that in the constructor I use the current viewdata "new ViewDataDictionary(this.ViewData)" which is a viewdatadictionary containing the modelstate that I need for the validationmessages.

提交回复
热议问题