You need to write code in your View something like:
@using (Html.BeginForm())
{
@Html.DropDownList("Animal Type",
new SelectList((System.Collections.IEnumerable)ViewData["Animal"], "animal_type"))
}
<div id="animalForm">
</div>
<script>
$("#Animal_Type").click(function () {
var selectedAminal = $("#Animal_Type").val();
alert(selectedAminal);
$.ajax({
url: "/Home/AnimalPartialView",
data: { animalName: selectedAminal },
type: 'Get',
success: function (msg) {
$("#animalForm").empty().append(msg);
},
error: function () {
alert("something seems wrong");
}
});
});
</script>
AnimalPartialView would be name of the action method. Now implement action method in Controller as shown below:
[HttpGet]
public ActionResult AnimalPartialView(string animalName)
{
return PartialView("AnimalPartialView", animalName);
}
Finally add a partial view named as AnimalPartialView. Write the below lines of code in AnimalPartialView partial view.
@model System.String
<span>@Model</span>
For more information on partial view visit below link.
CRUD Operations using Partial View and jQueryUI in ASP.NET MVC4 - Part 1[
^]
Thanks.