我想将 a 传递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 %>
这是代表 Model.FormModel 的视图模型
public class FormViewModel {
public string Action { get; set; }
public string Controller { get; set; }
public string Method { get; set; }
public RouteValueDictionary RouteValues { get; set; }
}
知道为什么它没有将 RouteValueDictionary 序列化为操作的正确 URL 吗?我想在这里使用一个对象,而不是手动构建 RouteValuesnew { field = vale }