Asp.net mvc 4 如何在MVC4中使用ajax jquery将viewbag值发布到post方法?

Asp.net mvc 4 如何在MVC4中使用ajax jquery将viewbag值发布到post方法?,asp.net-mvc-4,Asp.net Mvc 4,我正在检索ViewBag中的值列表,并在adropdownlist中显示ViewBag值,但我无法在HttpPost操作中发布dropdownlist值。如果我使用的是传递给HttpPost操作的按钮值,那么ajax jquery不会传递值。请帮帮我 $document.readyfunction{ $refresh.change函数{ $.ajax{ 类型:POST,, url:'@url.Actionupdate,主页', }; e、 防止违约; }; }; @使用Html.begin {

我正在检索ViewBag中的值列表,并在adropdownlist中显示ViewBag值,但我无法在HttpPost操作中发布dropdownlist值。如果我使用的是传递给HttpPost操作的按钮值,那么ajax jquery不会传递值。请帮帮我

$document.readyfunction{ $refresh.change函数{ $.ajax{ 类型:POST,, url:'@url.Actionupdate,主页', }; e、 防止违约; }; }; @使用Html.begin { 对于int i=0;i} 这就是它的工作原理:

第一控制器:

public ActionResult Index()
{
// put data into Viewbag
ViewBag.StateType = methodThatReturnsSelectList();
return View();
}
之所以使用Index.cshtml,是因为视图没有参数,并且控制器的名称是Index

@using (Html.BeginForm())
    {
        for (int i = 0; i < Model.Count(); i++)
        { 

  @Html.DropDownList("StateType", ViewBag.StateType as SelectList, new { @id = "refresh" })


        }
<script type="text/javascript">
       $(document).ready(function () {
           $("#refresh").change(function (e) {
               $.ajax(
                {
                    type: "POST",
                    url: '@Url.Action("update", "Home")',
                    data: $( "#myselect" ).val();
                });

               e.preventDefault();
           });
       });
    </script>

我认为它将阐明如何做,并对您有所帮助。

您在ajax调用中没有传递任何数据。我建议阅读一些关于jQueryAjax的教程。
[HTTPOST]
public ActionResult Update(string value)
{
// doing stuff
}