1

I'm fairly new to MVC, and need help understanding partial updates implementation similar to UpdatePanel functionality.

I have certain filters on the LHS of the page and a table(DataTable) on the RHS. When the user selects a filter, I want the table data to change according to the filter. I'm trying to load only the PartialView containing the table instead of loading the whole page. However, I am running into difficulties at the beginning itself.

Questions -

Can something like this be achieved using Html.BeginForm? Like shown here. I can't really find detailed documentation on Html.BeginForm, the MSDN site explains the technicalities, but I'm really not sure whether it is necessary to always use it, and where it is absolutely required.

What I've tried -

I've tried using jQuery.load() shown here. However, when I try to load my partial view like this, i run into a 400 Bad Request error.

All I'm doing here is -

In the View -

I've tried this -

$('#contentDiv').load('<%= @Url.Action("Index", "Grid") %>');  

and this -

$.post('<%= @Url.Action("Index", "Grid")%>', function (data) {
        $('#contentDiv').html(data);   }

I've also tried using #get and that doesnt work either.

In the controller -

    public ActionResult Index()
    {
        List<Models.GridData> tableData= new List<GridData>();
        try
        {                
            tableData= hvUtil.FillGrid();
            return PartialView(notes);               
        }
        

Can anyone suggest how to get things working?

Community
  • 1
  • 1
neuDev33
  • 1,573
  • 7
  • 41
  • 54

1 Answers1

2

It looks like you're using an odd combination of Razor and ASCX syntax. Have you looked at the javascript that gets generated?

This will probably get you closer to what you want:

$('#contentDiv').load('@Url.Action("Index", "Grid")');  
StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315
  • Oh my god! THAT was the issue? I have been searching examples online, and most of them had this syntax. Not having worked in this framework enough, I didnt realize this! Thank-you so much. I will accept this as the answer soon! – neuDev33 Jul 12 '12 at 18:39
  • @neuDev33: Yeah, when you see `<%= %>`, `<%: %>`, or `<% %>` syntax, that's intended for .ascx files. Razor replaces all of these alligator-style tags with `@...`, `@(...)`, or `@{...}`, depending on context. – StriplingWarrior Jul 12 '12 at 18:43