[英]C# MVC disable binding Controller Method Name to Action property of the model
问题是 - 我的控制器将方法名称绑定到我模型的“Action”属性,当然它会导致我的模型状态出错,因为Method Name 是 String而我的Action 属性是 Object 。 当我的 Formdata 中不存在 Action 属性时,我希望它为 null。
表格数据:
处理 POST 请求时的模型状态:
我的控制器动作:
[HttpPost]
public ActionResult RouteRoleActionsSave(TskRouteRoleAction model,List<TskAction.Actions> RoleActions = null)
{
using (var context = new SmartDbContext())
{
if (ModelState.IsValid)
{
return Json("ok");
}
return Json(ModelState);
}
}
我的型号:
[Table("TSK_ROUTE_ROLE_ACTIONS")]
public class TskRouteRoleAction
{
[Key, Column("ROUTE_ID", Order = 0), ForeignKey("Route")]
public decimal RouteId { get; set; }
public TskRoute Route { get; set; }
[Key, Column("ROLE_ID", TypeName = "numeric", Order = 1), ForeignKey("Role")]
public TskRole.Roles? RoleId { get; set; }
public TskRole Role { get; set; }
[Key, Column("ACTION_ID", TypeName = "numeric", Order = 2), ForeignKey("Action")]
public TskAction.Actions? ActionId { get; set; }
public TskAction Action { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.