Asp.net mvc 3 asp.net mvc 3远程属性传递3个字段

Asp.net mvc 3 asp.net mvc 3远程属性传递3个字段,asp.net-mvc-3,attributes,Asp.net Mvc 3,Attributes,我想使用RemoteAttribute将三个字段传递给我的控制器。我怎么做 public int ID1 { get; set; } public int ID2 { get; set; } [Remote("CheckTopicExists", "Groups", AdditionalFields = "ID1", ErrorMessage = " ")] public string Topic { get; set; } public Actio

我想使用RemoteAttribute将三个字段传递给我的控制器。我怎么做

 public int ID1 { get; set; }  
 public int ID2 { get; set; }  

 [Remote("CheckTopicExists", "Groups", AdditionalFields = "ID1", ErrorMessage = " ")]  
 public string Topic { get; set; }   

        public ActionResult CheckTopicExists(string topic, int ID1,int ID2)   
        {
            return Json(true, JsonRequestBehavior.AllowGet);
        }

如何将三个字段传递给该函数?

您可以用逗号分隔它们:

AdditionalFields = "ID1, ID2"
完整示例:

型号:

public class MyViewModel
{
    public int ID1 { get; set; }
    public int ID2 { get; set; }

    [Remote("CheckTopicExists", "Home", AdditionalFields = "ID1, ID2", ErrorMessage = " ")]
    public string Topic { get; set; }
}
控制器:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View(new MyViewModel
        {
            ID1 = 1,
            ID2 = 2,
            Topic = "sample topic"
        });
    }

    [HttpPost]
    public ActionResult Index(MyViewModel model)
    {
        return View(model);
    }

    public ActionResult CheckTopicExists(MyViewModel model)
    { 
        return Json(false, JsonRequestBehavior.AllowGet); 
    }
}
视图:

@model MyViewModel
@使用(Html.BeginForm())
{
@EditorFor(x=>x.ID1)
@EditorFor(x=>x.ID2)
@LabelFor(x=>x.Topic)
@EditorFor(x=>x.Topic)
@Html.ValidationMessageFor(x=>x.Topic)
}
而不是使用

public ActionResult CheckTopicExists(MyViewModel model)
如果你使用

public ActionResult CheckTopicExists(FormCollection Collection)

然后你也可以将代码用于其他类

注意发送日期,有时控制器接收日期的格式错误:was dd/mm/yyyy,receive mm/dd/yyyyy

@Avinash,太好了,如果对你有帮助,也许你可以将这篇文章标记为答案?@DarinDimitrov Avinash死了。无论如何,非常感谢。它帮助了我。
public ActionResult CheckTopicExists(FormCollection Collection)