Solved

Updating HTML using c# razor syntax

Posted on 2014-04-29
2
268 Views
Last Modified: 2014-05-13
I currently have a div class 'updatedContent' that is populated from the results of a razor HTML action "@Html.Action("test", "test2", new { isEditable = false }) my solution is in .net MVC 4.0 and I am looking at using something like jquery .load() or Ajax.

At the moment this gets populated on load but what I need is for this to get triggered as part of an on click event on a button.

I am familiar with jquery but not using it with c# and razor syntax.

Please can someone help?

Thanks
0
Comment
Question by:Al4ddin2
2 Comments
 

Author Comment

by:Al4ddin2
Comment Utility
Any ideas from anyone? Sorry to pester

Thanks
0
 
LVL 23

Accepted Solution

by:
Ioannis Paraskevopoulos earned 500 total points
Comment Utility
Hi,

Lets say you have a GET method called MyGet on your Controller.

You also need to give an ID, ie "Results" on your div.

In your View have the following where you want your button:

@using(Ajax.BeginForm("MyGet", new AjaxOptions { UpdateTargetId = "Results", InsertionMode = InsertionMode.Replace, HttpMethod = "Get" }))
{
    <input type="submit" value = "Refresh" />
}

Open in new window


Giannis
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now