How do I call a post actionresponse passing the selected dropdown item as a parameter from javascript within a view within asp.net, razor, mvc
Basically, as I'm sure you can tell from the below code, I'm trying to accomplish the above without much success. What should I change to be successful? Thanks
<script type="text/javascript">
$(function() {
$("#mydropdown").change(function() {
var selectedItem = $(this).val();
$.ajax({
url: '@Url.Action("DoStuff", "MainController")',
type: "Post",
data: { name: selectedItem },
success: function () {
alert('success');
}
});
});
});
[HttpPost]
public ActionResult DoStuff(String Selecteditem)
{
CIModel CIModellList = CILHelper.ImportFunc(Selecteditem);
return View(CIModellList);
}
As of now, nothing happens whem the dropdown is changed. Although if I remove the ajax function, and replace this with an alert. Then the alert in this case does appear.
At this point, both the actionresult and the controller appear as though they do not exist (red) within the project even though both do and are named as stated.
The c# seems to suggest neither the action or the controller actually exist, giving the errors "cannot resolve action" or "cannot resolve controller"