JORGE
JORGE

Reputation: 13

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

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

Upvotes: 0

Views: 2006

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039238

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.

Upvotes: 1

Related Questions