从ViewBag添加@ Html.TextBox值 [英] Add @Html.TextBox value from ViewBag

查看:855
本文介绍了从ViewBag添加@ Html.TextBox值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯使用MVC 3 asp.net

Im using MVC 3 asp.net

我如何从 ViewBag 将项目添加到 html.TextBox 是这样的:

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

@Html.TextBox("txtName",@ViewBag.Parameters.Name)

我想这太:

@Html.TextBox("txtName","@(ViewBag.Parameters.Name)")

似乎没有任何工作。

nothing seems to work.

有什么建议?

推荐答案

以期刚

@{
    ViewBag.Title = "Index";
}

@Html.TextBox("txtTitle", (string)ViewBag.Title)

正常工作与我(注意viewbag数据串的造型,因为扩展方法不能进行动态调度。)你也将显然必须改变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

这篇关于从ViewBag添加@ Html.TextBox值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆