Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to make a Partial view that displays data in a table.

I will have a Select element with the services to choose from.

When the user Selects a Service in the combobox I want to the call a partial view with the service Id number:

How can I do this?

Here is a action method which will render the partialView

//
// GET: /Service/ServiceStatusLogs/1
public ActionResult ServiceStatusLogs(int id)
{
   var db = new EFServiceStatusHistoryRepository();
   IList<ServiceStatusHistory> logs = db.GetAllStatusLogs(id);
   return View("_ServiceStatusLogs", logs);
 }

Here is the main action method which returns the page:

//
// GET: /Services/Status
public ActionResult Status()
{
  IList<Service> services;
  using (var db = new EFServiceRepository())
  {
    services = db.GetAll();
  }
   return View(services);
}
share|improve this question
    
You might find help in this article stackoverflow.com/questions/1570127/… –  ayheber Feb 27 '14 at 9:32

2 Answers 2

up vote 3 down vote accepted

You can make use $.ajax functionality to achieve, check this :-

      //Combo box change event
      $("#comboboxName").change(function () {        
            //Get service Id 
            var serviceId = $("#comboboxName").val();

            //Do ajax call  
            $.ajax({
            type: 'GET',
            url: "@Url.Content("/Service/ServiceStatusLogs/")",    
            data : {                          
                        Id:serviceId  //Data need to pass as parameter                       
                   },           
            dataType: 'html', //dataType - html
            success:function(result)
            {
               //Create a Div around the Partial View and fill the result
               $('#partialViewContainerDiv').html(result);                 
            }
         });           
     });

Also you should return partial view instead of view

//
// GET: /Service/ServiceStatusLogs/1
public ActionResult ServiceStatusLogs(int id)
{
   var db = new EFServiceStatusHistoryRepository();
   IList<ServiceStatusHistory> logs = db.GetAllStatusLogs(id);
   return PartialView("_ServiceStatusLogs", logs);
 }
share|improve this answer

Try this:

public ActionResult ServiceStatusLogs( int id )
{   
    //Prepare your model
    return PartialView( "UserDetails", model );
}

Any then use javascript(ajax) to load contents for an element of the DOM:

$('#user_content').load('/Service/ServiceStatusLogs');
share|improve this answer
    
I tried this but now my Jquery.datatable is not working on the table. I load the table with the partial view. How can I fix this? –  Zapnologica Feb 27 '14 at 11:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.