Solved

Loading partial view from a drop down list

Posted on 2016-09-05
2
26 Views
Last Modified: 2016-09-10
View partial view depending on drop down list selected value in mvc 5
0
Comment
Question by:aqms
2 Comments
 
LVL 19

Accepted Solution

by:
Manoj Patil earned 500 total points
ID: 41786080
Hey Check below link

http://stackoverflow.com/questions/11774741/load-partial-view-depending-on-dropdown-selection-in-mvc3

With above link reference,

Assuming you have a dropdown:

@Html.DropDownListFor(
    x => x.ItemId,
    new SelectList(Model.Items, "Value", "Text"),
    new { 
        id = "myddl", 
        data_url = Url.Action("Foo", "SomeController")
    }
)

Open in new window


you could subscribe for the .change() event of this dropdown and send an AJAX request to a controller action which will return a partial and inject the result into the DOM:

<script type="text/javascript">

$(function() {
   $('#myddl').change(function() {
       var url = $(this).data('url');
       var value = $(this).val();
       $('#result').load(url, { value: value })
    });
});

</script>

Open in new window


And place a DIV tag where you want the partial view to render in your host view:
<div id="result"></div>

Open in new window


and inside the Foo action you could return a partial view:
public ActionResult Foo(string value)
{
    SomeModel model = ...
    return PartialView(model);
}

Open in new window

0
 

Author Comment

by:aqms
ID: 41792629
thanks alot for helping
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now