Reputation: 5552
I have Select box and when user select item of Select box it fires Partial View Dynamically.
My Plan is create ActionLinks inside each option items. I already created my partial views. I don't have plan to create separate controller actions for that partial views.I want to call partial views when user select option items like
@Html.ActionLink("Link for my Partial View")
method or something like this.
How i do this with Razor? Are there any another ways to do this?
edit:There are 12 partial views available to render, so Is there any way to run code without Action and I want to fire the partial view without click submit button?
Upvotes: 0
Views: 1651
Reputation: 111
you can try - first need to get selected value changed of select box and then call action from your controller
On Controller (HomeController)
public PartialViewResult PartialViewTest()
{
return PartialView();
}
On View
<select>
<option value="0">One</option>
<option value="1">Two</option>
<script>
$("select").change(function () {
$.get('@Url.Action("PartialViewTest", "Home")', function (data) {
$('#detailsDiv').replaceWith(data);
});
}).trigger('change');
Hoping it can help you
Upvotes: 1
Reputation: 6858
you can change using jquery like that.
@Html.DropDownList("DropDownCategory", new SelectList(Model.Category, "ID", "Name"))
@Html.ActionLink("Submit name", "ActionName", "ControllerName", null, new { @id = "SubmitName" })
<script type="text/javascript">
$('#SubmitName').click(function () {
var value = $('#DropDownCategory').val();
var path = '@Url.Content("~/ControllerName/ActionName")' + "?CategoryId=" + value
$(this).attr("href", path);
});
</script>
Upvotes: 1