1 Replies - 386 Views - Last Post: 17 September 2017 - 02:17 AM

#1 hers  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-June 16

Refresh Partial View

Posted 16 September 2017 - 02:06 AM

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.

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


Controller

public ActionResult (int id)
{
   var test = db.Users.Where(e => e.cId = id);
 
   return PartialView(" _UserPartialView", test);
} 


Please help.

Thanks

This post has been edited by hers: 16 September 2017 - 02:06 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Refresh Partial View

#2 andrewsw  Icon User is offline

  • the case is sol-ved
  • member icon

Reputation: 6376
  • View blog
  • Posts: 25,763
  • Joined: 12-December 12

Re: Refresh Partial View

Posted 17 September 2017 - 02:17 AM

"Is not working" in what way? What happens? What do your browser's developer tools tell you about the get request and its returned content?

I haven't attempted what you are. It is more typical for an Ajax request to return the data and use jQuery to re-populate the dropdown.

I suppose, logically, it could be made to work (possibly), given that a Partial View is, essentially a fragment of HTML, but a Partial View to my understanding is always included as part of a View. I'm not convinced that returning it will resolve to a clean fragment of HTML. Have you used a tutorial that demonstrates this approach working?

(Are you following a book or substantial tutorial?)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1