Solved

Updating HTML using c# razor syntax

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…

930 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

14 Experts available now in Live!

Get 1:1 Help Now