Solved

Updating HTML using c# razor syntax

Posted on 2014-04-29
2
273 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
ID: 40029920
Any ideas from anyone? Sorry to pester

Thanks
0
 
LVL 23

Accepted Solution

by:
Ioannis Paraskevopoulos earned 500 total points
ID: 40031215
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The viewer will learn how to dynamically set the form action using jQuery.
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)

785 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