我是 asp.net MVC 4 的新手。我在處理屬性時遇到了一些問題
我在我的控制器中使用 [httppost] 屬性,但動作不觸發
我的觀點
![asp.net mvc [HttpPost] 沒有觸發](https://img.uj5u.com/2022/09/15/7afc4404c6a940fca7e8ab86ea4fe9c5.png)
我的控制
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(TourismCategory Info)
{
if (ModelState.IsValid)
{
return RedirectToAction("Index");
}
else
{
return View();
}
}
想你的幫助
uj5u.com熱心網友回復:
發布操作應該像這樣基于您的問題
[HttpPost]
public ActionResult Create([Bind(Include = "category,imagepth")]TourismCategory Info)
{
if (ModelState.IsValid)
{
db.TourisamCategory.Add(Info); // declare your dbcontext in the appropirate place
db.SaveChanges();
return RedirectToAction("Index");
}
else
{
return View(Info); // return the model if save failed
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/508229.html
標籤:asp.net-mvc
