当我想从用户提交值填充时,我该怎么办? 并将其发送到返回局部视图的ActionResult控制器
- 查看调用控制器的代码(来自文章)
<script language="JavaScript" type="text/javascript">
$('#centerbody').load('/Custom/CustomAction', function(html) {
$('#centerbody')[0].value = html;
});
</script>
- 没有参数的控制器动作(来自文章)
public ActionResult CustomAction()
{
return View("_CustomParialView");
}
感谢您的建议
答案 0 :(得分:0)
load函数的第二个参数表示一个哈希,允许您传递其他参数以及AJAX请求:
<script type="text/javascript">
$(function() {
$('#centerbody').load(
'/Custom/CustomAction',
{
// suppose that you have a text input with id: someInputId
// The value entered by the user in this field will be
// passed along the request in someParam
someParam: $('#someInputId').val()
}
);
});
</script>
在您的控制器操作中,您可以添加someParam
以检索AJAX调用传递的值:
public ActionResult CustomAction(string someParam)
{
// someParam will be passed from jQuery
return PartialView("_CustomParialView");
}