Solved

Updating HTML using c# razor syntax

Posted on 2014-04-29
2
278 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
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…

808 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