English 中文(简体)
Using jquery to get a partial view and updating the UI
原标题:

I need to render a partial view (returned from the controller) to show some customer summary details. This will need to happen when the user clicks on a button. In the the mean time the user can select different customers on a grid. I keep note of the selected customer id in a hidden field using jquery on the grids selection changed event. When the user clicks on a button i need to pass this hidden field value (selected id) to the controller, the controller does some work and returns a partial view. I then need to render this partial view on the page. I have tried the following but have two problems

  1. I cant fig out how to send the hidden field value to the controller
  2. After the partial view is rendered I cant get it to rerender if the user selects another customer and clicks the button again

The code:

  #PlaceHolder is just a div element

function DoSomwWork() {
                $( #PlaceHolder )
                .load( <%= Url.Action("GetSelectedCustSummary", 
                                      "SomeController", 
                                       new { selectedId = **HIDDEN FIELD VAL HERE** })%> );
            }
        }
问题回答

I doubt you will be able to do it this way.

However since you are already using MVC, you shall be able to define a action ("GetSelectedCustSummary"in your case) and return a json object instead, then manipulate it with your jQuery

Update: Define Action Method something like:

[HttpGet]
public JsonResult ActionName(string id)
{
    //some logic here to get QueryResult
    return Json(QueryResult, JsonRequestBehavior.AllowGet);
}

then call your Action Method in Jquery:

$.ajax({
    //you can assign id dynamically
    url:  <%= Url.Content("~/Controller/ActionName/YourId") %> ,
    type:  GET ,
    dataType:  json ,
    success: function (data) {
       //manipulate your div content with data
    },
    error: function (e) {
        //manipulate your div content with error
    }
});

Every time you click update button, assign the id you want, and trigger the Jquery function. It worked for me in my project





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签