[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Loading partial view from a drop down list

Posted on 2016-09-05
2
Medium Priority
?
266 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 1500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month17 days, 21 hours left to enroll

829 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