开发者

JQuery and Patial view in MVC

Belong to this article Jquery Partial View

What should i do when i want to submit the value fill from user and sent it to the ActionResult controller that return the partial view

-- View Code that call the controller (from article)

<script language="JavaScript" type="text/javascript">
   $('#centerbody').load('/Custom/CustomAction', function(html) {
       $('#centerbody')[0].value = html;  
   });
</script>

-- Controller Action with no parameter (from article)

public ActionResult CustomAction()
{
  return View("_CustomParialView");
}

Thanks fo开发者_开发百科r your suggestion


The second argument of the load function represents a hash allowing you to pass additional parameters along with the AJAX request:

<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>

And in your controller action you could add someParam in order to retrieve the value passed by the AJAX call:

public ActionResult CustomAction(string someParam)
{
    // someParam will be passed from jQuery
    return PartialView("_CustomParialView");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜