Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ajax 在服务器上创建RouteValueDictionary并在aspx中使用?_Ajax_Asp.net Mvc 2_Ajax.beginform - Fatal编程技术网

Ajax 在服务器上创建RouteValueDictionary并在aspx中使用?

Ajax 在服务器上创建RouteValueDictionary并在aspx中使用?,ajax,asp.net-mvc-2,ajax.beginform,Ajax,Asp.net Mvc 2,Ajax.beginform,我正试图将一个RouteValueDictionary传递给我的aspx,这样我就可以将它用作Ajax.BeginForm方法的参数。我是这样装的: RouteValues = new System.Web.Routing.RouteValueDictionary(); RouteValues.Add("FindingId", thisFinding.Id); RouteValues.Add("ReportId", thisFinding.ReportSection.ReportId);

我正试图将一个
RouteValueDictionary
传递给我的aspx,这样我就可以将它用作
Ajax.BeginForm
方法的参数。我是这样装的:

 RouteValues = new System.Web.Routing.RouteValueDictionary();

 RouteValues.Add("FindingId", thisFinding.Id);
 RouteValues.Add("ReportId", thisFinding.ReportSection.ReportId);
然后将其添加到我的模型中,没有问题。当我将其作为
BeginForm
方法的参数时,它将操作呈现如下:

/SolidWaste/Finding/LoadSection?Count=3&Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D
以下是aspx代码:

(Ajax.BeginForm(Model.FormModel.Action,
    Model.FormModel.Controller, 
    Model.FormModel.RouteValues,
new AjaxOptions {
    HttpMethod = "Post",
    InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace,
    UpdateTargetId = "WindowContent",
}, new { id = FormId })) { %>
<input name="submit" type="submit" class="button" value="" style="float: right;"/>
<%  } //End Form %>

知道为什么它没有将RouteValueDictionary序列化为操作上的正确URL吗?我想在这里使用一个对象,而不是使用
new{field=vale}

手动构建RouteValue,啊,您使用了错误的重载。这很正常。ASP.NETMVC团队真的把这个API搞得一团糟。你必须小心你调用的方法。以下是您需要的:

<% using (Ajax.BeginForm(
    Model.FormModel.Action,                                // actionName
    Model.FormModel.Controller,                            // controllerName
    Model.FormModel.RouteValues,                           // routeValues
    new AjaxOptions {                                      // ajaxOptions
        HttpMethod = "Post",
        InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace,
        UpdateTargetId = "WindowContent",
    }, 
    new Dictionary<string, object> { { "id", FormId } })    // htmlAttributes
) { %>
    <input name="submit" type="submit" class="button" value="" style="float: right;"/>
<% } %>

注意正确的重载吗?您使用的是一个将
routeValues
htmlAttributes
作为匿名对象的对象,只是将
Model.FormModel.routeValues
作为
RouteValueDictionary
传递,基本上消除了您的重载


点击F12,同时将光标悬停在
BeginForm
上,如果您足够幸运,并且Intellisense在Razor视图中运行良好(这种情况很少发生),您将被重定向到实际调用的方法,并意识到您的错误。

哇,真是一个大错误。我不敢相信它真的仅仅是指定HTMLAttributes是Dictionary类型。。。非常感谢您,尤其是您的快速回复!我能够用模型中的实际字典替换新的RouteValueDictionary(),并且工作正常。
<% using (Ajax.BeginForm(
    Model.FormModel.Action,                                // actionName
    Model.FormModel.Controller,                            // controllerName
    Model.FormModel.RouteValues,                           // routeValues
    new AjaxOptions {                                      // ajaxOptions
        HttpMethod = "Post",
        InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace,
        UpdateTargetId = "WindowContent",
    }, 
    new Dictionary<string, object> { { "id", FormId } })    // htmlAttributes
) { %>
    <input name="submit" type="submit" class="button" value="" style="float: right;"/>
<% } %>