Note that there are some explanatory texts on larger screens.

plurals
  1. POPosting model data from one View to another in mvc3 using ajx
    primarykey
    data
    text
    <p>I want to transfer model data from one View to another View (in a dialog) using Ajax.Actionlink were i am getting null values on Post Action </p> <p>This is my View</p> <pre><code>@using (Ajax.BeginForm("", new AjaxOptions { })) { for (int i = 0; i &lt; Model.city.Count; i++) { &lt;div class="editor"&gt; &lt;p&gt; @Html.CheckBoxFor(model =&gt; model.city[i].IsSelected, new { id = "check-box-1" }) @Html.HiddenFor(model =&gt; model.city[i].Id) @Ajax.ActionLink(Model.city[i].Name, "PopUp", "Home", new { @class = "openDialog", data_dialog_id = "emailDialog", data_dialog_title = "Cities List", }, new AjaxOptions { HttpMethod = "POST" }) @Html.HiddenFor(model =&gt; model.city[i].Name) &lt;/p&gt; &lt;/div&gt; } } </code></pre> <p>On using Ajax.Actionlink i am creating a dialog using ajax scripting</p> <p>My controller class for this View is </p> <pre><code> public ActionResult Data() { var cities = new City[] { new City { Id = 1, Name = "Mexico" ,IsSelected=true}, new City { Id = 2, Name = "NewJersey",IsSelected=true }, new City { Id = 3, Name = "Washington" }, new City { Id = 4, Name = "IIlinois" }, new City { Id = 5, Name = "Iton" ,IsSelected=true} }; var model = new Citylist { city = cities.ToList() }; //this.Session["citylist"] = model; return PartialView(model); } </code></pre> <p>another View for displaying Post action data is</p> <pre><code> @model AjaxFormApp.Models.Citylist @{ ViewBag.Title = "PopUp"; } &lt;h2&gt; PopUp&lt;/h2&gt; &lt;script type="text/javascript"&gt; $(function () { $('form').submit(function () { $.ajax({ url: this.action, type: this.method, data: $(this).serialize(), success: function (result) { var checkedAtLeastOne = false; $('input[id="check-box-2"]').each(function () { if ($(this).is(":checked")) { checkedAtLeastOne = true; // alert(checkedAtLeastOne); } }); if (checkedAtLeastOne == true) { // alert("Test"); $('#div1').show(); $(".dialog").dialog("close"); } else { // alert("NotSelected"); $('#div1').hide(); $('#popUp').html(result); $('#popUp').dialog({ open: function () { $(".ui-dialog-titlebar-close").hide(); }, buttons: { "OK": function () { $(this).dialog("close"); } } }); } } }); return false; }); }); &lt;/script&gt; &lt;div style="display: none" id="div1"&gt; &lt;h4&gt; Your selected item is: &lt;/h4&gt; &lt;/div&gt; @using (Ajax.BeginForm(new AjaxOptions { })) { for (int i = 0; i &lt; Model.city.Count; i++) { &lt;div class="editor"&gt; &lt;p&gt; @Html.CheckBoxFor(model =&gt; model.city[i].IsSelected,new { id = "check-box-2" }) @Html.HiddenFor(model =&gt; model.city[i].Id) @Html.LabelFor(model =&gt; model.city[i].Name, Model.city[i].Name) @Html.HiddenFor(model =&gt; model.city[i].Name) &lt;/p&gt; &lt;/div&gt; } &lt;input type="submit" value="OK" id="opener" /&gt; } @*PopUp for Alert if atleast one checkbox is not checked*@ &lt;div id="popUp"&gt; &lt;/div&gt; </code></pre> <p>and my post controller action result class is</p> <pre><code> [HttpPost] public ActionResult PopUp(Citylist model) { if (Request.IsAjaxRequest()) { //var model= this.Session["citylist"]; return PartialView("PopUp",model); } return View(); } </code></pre> <p>My model class is</p> <pre><code>public class City { public int Id { get; set; } public string Name { get; set; } public bool IsSelected { get; set; } } public class Citylist { public IList&lt;City&gt; city { get; set; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload