嘗試使用 DataAnnotations 在模型中提交具有自定義驗證集的表單時,我收到錯誤消息“找不到路徑'/ItemController/IsAssetAvailable' 的控制器或未實現 IController”??刂破鞑季郑嚎刂破鞔a:public ActionResult IsAssetAvailable(string Asset_Tag_Nbr) { using (db) { try { var asset = db.Items.Single(i => i.Asset_Tag_Nbr == Asset_Tag_Nbr); return Json(false, JsonRequestBehavior.AllowGet); } catch (Exception) { return Json(true, JsonRequestBehavior.AllowGet); } } }數據注釋:[Display(Name = "Asset Tag #")][Remote("IsAssetAvailable", "ItemController", ErrorMessage = "Asset # already exists.")]public string Asset_Tag_Nbr { get; set; }看法:<div class="form-group col-sm-4"> @Html.LabelFor(model => model.Asset_Tag_Nbr, new { @class = "control-label col-md-12" }) <div class="col-md-10"> @Html.EditorFor(model => model.Asset_Tag_Nbr, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Asset_Tag_Nbr) </div></div>
1 回答

一只萌萌小番薯
TA貢獻1795條經驗 獲得超7個贊
問題似乎來自內部聲明的控制器名稱,RemoteAttribute如下所示:
[Remote("IsAssetAvailable", "ItemController", ErrorMessage = "Asset # already exists.")]
public string Asset_Tag_Nbr { get; set; }
您正在使用RouteAttribute 2 個重載:
public RemoteAttribute (string action, string controller)
參數是控制器名稱,包含對應的controller動作方法名稱,不帶Controller后綴。因此,您應該使用RouteAttribute如下示例的參數:
[Display(Name = "Asset Tag #")]
[Remote("IsAssetAvailable", "Item", ErrorMessage = "Asset # already exists.")]
public string Asset_Tag_Nbr { get; set; }
- 1 回答
- 0 關注
- 167 瀏覽
添加回答
舉報
0/150
提交
取消