Add @Html.TextBox value from ViewBag

前端 未结 2 1080
再見小時候
再見小時候 2020-12-31 05:34

Im using MVC 3 asp.net

How can I add an item from ViewBag to html.TextBox like this:

@Html.TextBox(\"txtName\",@ViewBag.Par         


        
2条回答
  •  悲哀的现实
    2020-12-31 05:40

    A View with just

    @{
        ViewBag.Title = "Index";
    }
    
    @Html.TextBox("txtTitle", (string)ViewBag.Title)
    

    works fine with me (notice the cast of the viewbag data to string because Extension methods cannot be dynamically dispatched.) also you will obviously have to change ViewBag.Title to your property

提交回复
热议问题