I want to pass three field to my controller using RemoteAttribute. How can i do it?
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);
}
How can i pass three field to that function?
You could separate them by comma:
AdditionalFields = "ID1, ID2"
Full example:
Model:
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; }
}
Controller:
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);
}
}
View:
@model MyViewModel
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
@using (Html.BeginForm())
{
@Html.EditorFor(x => x.ID1)
@Html.EditorFor(x => x.ID2)
@Html.LabelFor(x => x.Topic)
@Html.EditorFor(x => x.Topic)
@Html.ValidationMessageFor(x => x.Topic)
<input type="submit" value="OK" />
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With