0

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?

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.