Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 如何在视图中使用ViewBag_Asp.net Mvc 3 - Fatal编程技术网

Asp.net mvc 3 如何在视图中使用ViewBag

Asp.net mvc 3 如何在视图中使用ViewBag,asp.net-mvc-3,Asp.net Mvc 3,如何使用ViewBag显示“Name-LastName” <h2> @{ViewBag.Name;} - @{ViewBag.LastName;} </h2> @{ViewBag.Name;}-@{ViewBag.LastName;} 我有错误我不知道您通过ViewBag传递了什么,但请删除括号 <h2> @ViewBag.Name - @ViewBag.LastName </h2> @ViewBag.Name-@ViewBag.LastNa

如何使用ViewBag显示“Name-LastName”

<h2> @{ViewBag.Name;} - @{ViewBag.LastName;} </h2>
@{ViewBag.Name;}-@{ViewBag.LastName;}

我有错误

我不知道您通过ViewBag传递了什么,但请删除括号

<h2> @ViewBag.Name - @ViewBag.LastName </h2>
@ViewBag.Name-@ViewBag.LastName
@ViewBag.Name-@ViewBag.LastName
您只需要
@

我强烈建议您开始使用强类型视图,而不是使用ViewBag。强类型视图使视图(和代码)保持干净和可维护。

@ViewBag.Name-@ViewBag.LastName
<h2> @ViewBag.Name - @ViewBag.LastName </h2>
避免额外的{和你是好的

<h2> @ViewBag.Name - @ViewBag.LastName </h2>