我是MVC的新手并试图将数据从视图传递到页面并且遇到两个问题:
我的控制器看起来像这样:
public class CustomersController : Controller
{
public ActionResult Details(int? pageIndex)
{
var Name = "Nope";
if(pageIndex == 1)
{
Name = "John Smith";
};
return View(Name);
}
}
}
我的观点如下:
@{
ViewBag.Title = "Details";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Details</h2>
<p>@Model.Name</p>