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.
精彩评论