远程验证不适用于guid

时间:2012-08-15 09:25:55

标签: asp.net-mvc-3 remote-validation

[Remote("DropDownSelected", "Patient")]
public Guid SexIdentifier { get; set; }



public ActionResult DropDownSelected(object value)
{
    var x = ((Guid)value).ToString();
    string xsd = value.ToString();
    var abc = ControllerContext.Controller;

    if (value == null)
    {
        //value = string.Empty;
    }

    if (value.ToString() == Convert.ToString(Guid.Empty) || value.ToString() == string.Empty)
    {
        return Json(String.Format("0 does not exist."), JsonRequestBehavior.AllowGet);
    }

    return Json(true, JsonRequestBehavior.AllowGet);
}

1 个答案:

答案 0 :(得分:0)

如果您的属性被调用SexIdentifier,那么您的操作必须使用相同的名称作为其参数:

public ActionResult DropDownSelected(Guid sexIdentifier) 
{
    ...
}

此外,如果您有下拉列表的默认值,则可以使用可为空的Guid

public ActionResult DropDownSelected(Guid? sexIdentifier) 
{
    ...
}