/// <summary>
/// 验证角色名称唯一
/// </summary>
/// <param name="name"></param>
/// <returns>true验证通过</returns>
[HttpGet]
public JsonResult CheckName(string name)
{
string url = Request.UrlReferrer.OriginalString;
HttpRequest hr = new HttpRequest("", url, "");
HttpResponse hrs = new HttpResponse(new StringWriter());
HttpContext hc = new HttpContext(hr, hrs);
HttpContextWrapper hcw = new HttpContextWrapper(hc);
RouteData rd = RouteData.Route.GetRouteData(hcw);
string controllerName = rd.Values["controller"].ToString().ToLower();
string actionName = rd.Values["action"].ToString().ToLower();
string id = rd.Values["id"].ToString().ToLower();;
int actionID = string.IsNullOrEmpty(id) ? 0 : int.Parse(id);
bool result = true;
var role = _roleService.GetRole(name);
if (role != null)
{
if (actionID == 0)
result = false;// 添加
else
result = !_roleService.Entities.Any(r => r.Name.Equals(name) && r.ID != actionID);
}
return Json(result, JsonRequestBehavior.AllowGet);
}