开发者

MVC3 HOW TO PASS IN .load function of jquery the parameter include in url

开发者 https://www.devze.com 2023-03-31 18:23 出处:网络
How to pass in .load function of jquery, the parameter include in url. url recived in create.cshtml => http://.../Invoiced/Create/1

How to pass in .load function of jquery, the parameter include in url.

url recived in create.cshtml => http://.../Invoiced/Create/1 InvoicedDetail is a partialView , this contain list of details by id, this id is the paramet开发者_运维知识库er in ulr http://.../Invoiced/Create/1, how to cathc this parameter "1" to send in .load function ?

thanks.

Create.cshtml

    <p>Details list</p>

    <div id="InvoicedDetails_content"><div>

    <script language="javascript" type="text/javascript">
             $(document).ready(function () {
    //         parameter  = ?;
                $('#InvoicedDetails_content').load('/InvoicedDetail/Index/' + parameter);
            });

        </script>


Never hardcode urls or any string concatenations. Always use urls helpers when you need to generate a url in an ASP.NET MVC application:

<script type="text/javascript">
$(function() {
    var url = '@Url.Action("Index", "InvoicedDetail", new { id = ViewContext.RouteData.Values["id"] })';
    $('#InvoicedDetails_content').load(url);
});
</script>

In this example I am using the id parameter which assumes that you have this route parameter defined in your route definitions. Adapt the name if necessary.

0

精彩评论

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

关注公众号