我将路由配置文件ID更改为字符串
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Agent_default",
"Agent/{controller}/{action}/{id}",
new { Controller = "Home", action = "Index", id = "" }
);
}
现在我可以像我预期的那样得到我的网址http://localhost:43425/Agent/Accounts/Edit/A64h9lStdffgt
但是我在保存模型时遇到异常。
抛出异常ModelState.Isvalid - False
说:价值' A64h9lStdffgt'对于Id无效。怎么解决这个? ModelState.Isvalid如何工作?为什么我收到此错误?
由于
答案 0 :(得分:2)
代表@Stephen Muecke:
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Agent_Custom",
"Agent/{controller}/{action}/{number}",
new { Controller = "Home", action = "Index", number = "" }
);
context.MapRoute(
"Agent_default",
"Agent/{controller}/{action}/{id}",
new { Controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}