【发布时间】:2023-01-18 19:20:52
【问题描述】:
我是 ASP.NET MVC 的新手。您能解释一下 ActionResult 和 ViewResult 之间的区别吗?如果使用 ActionResult 作为我的操作的返回类型而不是视图,这有关系吗? 渲染视图和返回视图是什么意思?
这是两个动作。如果我将 Index() 类型从 ViewResult 更改为 ActionResult 会有影响吗?
public ViewResult Index()
{
var customers = GetCustomers();
return View(customers);
}
public ActionResult Details(int id)
{
var customer = GetCustomers().SingleOrDefault(c => c.Id == id);
if (customer == null)
return HttpNotFound();
return View(customer);
}
【问题讨论】:
标签: c# asp.net asp.net-mvc api asp.net-mvc-4