Html.EditorFor additionalViewData

后端 未结 2 1744
遥遥无期
遥遥无期 2020-12-30 18:46

I have a custom editor template where I add values to the ViewData like so:

@Html.EditorFor( model => model.PhoneNumber , new { Title = \"Som         


        
相关标签:
2条回答
  • 2020-12-30 18:52

    You can nest your htmlAttributes object in view data:

    <%= Html.EditorFor(model => model.PhoneNumber, new { htmlAttributes = new { Title = "SomeValue" } })
    

    Then in your editor template:

    <%= Html.TextBox("", Model.Value, ViewData["htmlAttributes"])%>
    
    0 讨论(0)
  • 2020-12-30 18:53

    ViewData is a dictionary.

    You can write ViewData["Title"], or you can loop through ViewData (which is a collection of KeyValuePairs) or ViewData.Keys.

    0 讨论(0)
提交回复
热议问题