Click here to Skip to main content
15,067,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am developing a Web Application with Asp.NET MVC5. As I dont have much experience, I am stuck with a functionality using JQuery and Partial View.

I have a Side Menu as a partial view in a page. This partial view contains a DropdownList which is populated from model, and it works fine. However, I want to display a list of items from the db when the dropdown is selected, based on the selection, which is not working.

Please help.

Thanks

What I have tried:

HTML
Partial View (_UserPartialView)
$('#dropdown').change(function(){
var item = $(this).val(); 
$.get("/Controller/GetItems/" +  item, function(data)
{
   ('#target').html(data); 
});

Controller
C#
public ActionResult (int id)
{
   var test = db.Users.Where(e => e.cId = id);
 
   return PartialView(" _UserPartialView", test);
}
Posted
Updated 17-Sep-17 13:15pm
v4

To get the "target" element as a jQuery item you need to do

$('#target').html(data);


If that still doesn't work then you need to do some debugging using the browser tools, check that "item" is what you expect, check the action is called, check the "test" variable has results, look for errors, exceptions etc.
   
There was a Tip just post here on CodeProject that will help: An MVC HTML helper to asynchronously load partial views[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900