Asp.net mvc 如何在Asp.net Mvc中打印视图页上的字符串数组?
我不知道如何在查看页面上获取此字符串。请帮帮我。您可以设置一个可视包Asp.net mvc 如何在Asp.net Mvc中打印视图页上的字符串数组?,asp.net-mvc,asp.net-mvc-4,Asp.net Mvc,Asp.net Mvc 4,我不知道如何在查看页面上获取此字符串。请帮帮我。您可以设置一个可视包 public ActionResult About() { var roles = System.Web.Security.Roles.GetAllRoles(); return View(); } 您可以通过@ViewBag.roles 显示列表 public ActionResult About() { ViewBag.roles
public ActionResult About()
{
var roles = System.Web.Security.Roles.GetAllRoles();
return View();
}
您可以通过@ViewBag.roles
显示列表
public ActionResult About()
{
ViewBag.roles = System.Web.Security.Roles.GetAllRoles();
return View();
}
您可以设置一个ViewBag
public ActionResult About()
{
var roles = System.Web.Security.Roles.GetAllRoles();
return View();
}
您可以通过@ViewBag.roles
显示列表
public ActionResult About()
{
ViewBag.roles = System.Web.Security.Roles.GetAllRoles();
return View();
}
View方法采用的模型可以是字符串[]
foreach(var customrole in ViewBag.roles)
{
@customrole.Roles // This might be some property you need to display
}
那么你的观点会是这样的
public ActionResult About()
{
var roles = System.Web.Security.Roles.GetAllRoles();
return View(roles);
}
View方法采用的模型可以是字符串[]
foreach(var customrole in ViewBag.roles)
{
@customrole.Roles // This might be some property you need to display
}
那么你的观点会是这样的
public ActionResult About()
{
var roles = System.Web.Security.Roles.GetAllRoles();
return View(roles);
}
您应该让视图接受字符串[]模型,并将此模型从控制器传递到视图,如下所示:
@model System.Array
@foreach (var role in Model)
{
...
}
在您看来,您可能会遇到类似的情况(假设您使用的是Razor ViewEngine):
@model string[]
@foreach(模型中的var角色)
{
- @角色
}
您应该让视图接受字符串[]模型,并将此模型从控制器传递到视图,如下所示:
@model System.Array
@foreach (var role in Model)
{
...
}
在您看来,您可能会遇到类似的情况(假设您使用的是Razor ViewEngine):
@model string[]
@foreach(模型中的var角色)
{
- @角色
}
以这种方式显示System.String[]作为查看页面上的输出。您必须反复查看列表我已更新了答案检查此帖子以这种方式显示ViewBag System.String[]作为查看页面上的输出。你必须遍历列表我已经更新了我的答案检查这篇文章显示foreach循环内的ViewBag必须使用“Model”。foreach循环内必须使用“Model”。