我是asp.net MVC的初学者
我有一个像这样的人类
public partial class Person
{
public int Id { get; set; }
public string Name { get; set; }
public string Family { get; set; }
public string WebSite { get; set; }
}
我有一个ActionResult创建如下
public ActionResult Create(Person person)
{
db.Person.Add(person);
db.SaveChanges();
return RedirectToAction("Index");
//retrun View (Index);
}
当我使用RedirectToAction时,“我的项目”运行没有任何错误,但是当我使用“返回 View ”时,我遇到了错误。这些有什么区别?
注意:索引 View 在“人员”表中显示所有信息
最佳答案
在您的Create方法中,它应该是POST方法。使用重定向的更好设计模式
重定向后获取模式。
请浏览此介绍Wikipedia : Post/Redirect/Get
关于c# - RedirectToAction()和View()有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61832739/