亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

嘗試在 MVC 5 中設置自定義驗證時出錯

嘗試在 MVC 5 中設置自定義驗證時出錯

C#
斯蒂芬大帝 2022-06-12 11:17:41
嘗試使用 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; }


查看完整回答
反對 回復 2022-06-12
  • 1 回答
  • 0 關注
  • 167 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號