Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET jQuery MVC3
I have a view that changes content without changing the overall view,
(change a portion of the view)
here is my code:

Models:
public class DisplayData
    {
        public int ID { get; set; }
        public DisplayData(int ID)
        {
            this.ID = ID;
        }
    }

Controllers:


public ActionResult PartialDemo(string Data)
        {
            List<DisplayData> Display = new List<DisplayData>();
 
            if (Request.IsAjaxRequest())
            {
                if (Data == "1")
                {
                    Display.Add(new DisplayData(3));
                    Display.Add(new DisplayData(4));
                }
                else
                {
                    Display.Add(new DisplayData(5));
                    Display.Add(new DisplayData(6));
                }
                return PartialView("PartialDemoUC", Display);
            }
            else
            {
                Display.Add(new DisplayData(1));
                Display.Add(new DisplayData(2));
                return View("PartialDemo", Display);
            }
        }

PartialDemoUC.cshtml
@model IEnumerable<dynamic>
 
@foreach(var items in Model)
{
   @items.ID    
}

PartialDemo.cshtml:

@model IEnumerable<AppTwitter.Models.DisplayData>
@{
    ViewBag.Title = "PartialDemo";
}
 
<script src="../../Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
@Ajax.ActionLink("Link_1", "PartialDemo", "PartialDemo", new {Data= "1" }, new AjaxOptions { UpdateTargetId = "rsvpmsg" })
@Ajax.ActionLink("Link_2", "PartialDemo", "PartialDemo", new {Data= "2" }, new  AjaxOptions { UpdateTargetId = "rsvpmsg" })
 
<div id="rsvpmsg">
@{ Html.RenderPartial("PartialDemoUC", this.Model);}
</div>


I will change Link_1 and Link_2 by a checkbox: if chechbox is checked it's like the link is clicked
how can i do this ?

I am sorry for my bad english

Thanks,
Posted 21-Jun-12 23:18pm
saisne505
Edited 21-Jun-12 23:38pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Basically, you want to use jQuery to watch the click event on the checkbox. When it is clicked, you want to have the jQuery method call your MVC method with the appropriate parameters. Here is a Stack Overflow question that has an example of how to do this in the given answer:

http://stackoverflow.com/questions/9185606/how-to-trigger-an-ajax-event-with-a-checkbox-click-in-asp-net-mvc[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 199
1 Sergey Alexandrovich Kryukov 154
2 Sascha Lefévre 120
3 Abhinav S 104
4 Rana Waqas 78
0 Sergey Alexandrovich Kryukov 6,628
1 OriginalGriff 6,298
2 Peter Leow 2,534
3 Maciej Los 2,437
4 Abhinav S 2,378


Advertise | Privacy | Mobile
Web02 | 2.8.150414.1 | Last Updated 22 Jun 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100