Tim*_*ong -1 c# asp.net-mvc asp.net-mvc-4
我似乎无法弄清楚为什么我的[HttpPost]Index()方法给我一个错误信息说明
并非所有代码路径都返回一个值
我尝试了return View()之后AddModelError但仍然给了我错误信息.
public class SnowboardController : Controller
{
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(SnowboardModel SbModel)
{
if (SbModel.DiscountSenior && SbModel.DiscountStudent)
{
ModelState.AddModelError("Discounts", "Dude, you cannot take both student and senior discounts.");
}
//return to view if any fields invalid
if (!ModelState.IsValid)
{
return View(SbModel);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我还在@Html.ValidationMessage("Discounts")我的观点中补充道.
| 归档时间: |
|
| 查看次数: |
685 次 |
| 最近记录: |