不幸的是,這是如何實現這個屬性。下面是該屬性的構造函數摘錄:
public RemoteAttribute(string action, string controller, string areaName) : this()
{
if (string.IsNullOrWhiteSpace(action))
{
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "action");
}
if (string.IsNullOrWhiteSpace(controller))
{
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "controller");
}
this.RouteData["controller"] = controller;
this.RouteData["action"] = action;
if (!string.IsNullOrWhiteSpace(areaName))
{
this.RouteData["area"] = areaName;
}
}
通知對areaName
在那的殺一切都結束了IsNullOrWhiteSpace
測試?
你可以通過編寫自定義的遠程屬性修正:
public class MyRemoteAttribute : RemoteAttribute
{
public MyRemoteAttribute(string action, string controller, string area)
: base(action, controller, area)
{
this.RouteData["area"] = area;
}
}
然後:
[MyRemote("IsValidUserName", "Validation", "", ErrorMessage = "Invalid username")]
public string Username { get; set; }
現在正確data-val-remote-url="/Validation/IsValidUserName"
將會產生。
謝謝您的解決方案。 – user644344 2011-03-13 18:36:55
你能告訴我在哪裏可以得到MVC的源代碼嗎? – user644344 2011-03-13 18:37:36
@ user644344,它可以在這裏找到:http://aspnet.codeplex.com/releases/view/58781。但是您也可以使用Reflector快速瀏覽程序集。 – 2011-03-13 19:42:54