我假设由于您没有在 Url.Action(...) 中提供路由值,因此您要发布到操作的数据正在由客户端上的用户设置?
如果是这样,一种非常简单的方法是创建一个带有隐藏字段的表单(或者如果您想要直接的用户交互,则可能是可见的),然后在排序上设置这些字段,然后提交表单。
例如:
<form id='sortform' action='@Url.Action("ActionName")' method='POST'>
<input type='hidden' name='MyFirstSortValue'>
<input type='hidden' name='MySecondSortValue'>
</form>
和:
function Sort() {
var formElem = document.getElementById('sortform');
formElem.MyFirstSortValue.value = "blah";
formElem.MySecondSortValue.value = "blah";
formElem.submit();
}
如果您只是让用户选择排序信息,那么我建议让表单输入可见并直接使用它们,而不是在调用 Sort 时间接设置它们。
完成上述操作后,您可以使用FormCollection通过控制器访问信息。例如:
[HttpPost]
public ActionResult ActionName(FormCollection form)
{
string myFirstSortValue = form["MyFirstSortValue"];
string mySecondSortValue = form["MySecondSortValue"];
// Do something to sort the data in the model...
return View(yourModel);
}
这将导致回发与正在传输的数据一起发生,并显示所需的视图。