ASP.NET MVC razor html出错
下面的Html.TextBox razor代码会出错
@using (Html.BeginForm())
{
}
Action代码
public ActionResult Demo2Index()
{
ViewData["name"] = Request["name"];
ViewBag.pwd = 123;
TempData["pwd"] = Request["pwd"];
return View();
}
ViewBag.pwd是dynamic动态类型,Html.TextBox的重载第二个参数没有dynamic,所以报错了。改下面
@Html.TextBox("passwd",ViewBag.pwd as int?)
注意给ViewBag赋值的类型,要不as转换无法转换为null值,其他2个同理转为string或者其他类型,不能直接使用dynamic.
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!