Reputation: 4487
In my Project i need to pass value partial value while click button. So i tried like this
<div id="searchgrid" class="col-lg-12">
@Html.Partial("ResultGrid", new List<SCM_MVC.Models.User>(),
new ViewDataDictionary(this.ViewData) { { "index" , xEdit } })
</div>
<script src="~/assets/js/jquery-1.10.2.js"></script>
<script>
var url = '@Url.Action("ResultGrid", "User")', new { xEdit : ViewData["Form"] };
$('#btnloadgrid').click(function () {
$('#searchgrid').load(url);
})
</script>
While open View its Working. But Click button its not working. What am doing wrong in jquery function?
Upvotes: 0
Views: 688
Reputation: 24957
The url
declaration is syntactically wrong as checked in .NET fiddle:
var url = '@Url.Action("ResultGrid", "User")', new { xEdit : ViewData["Form"] };
// ^ Syntax error: Unexpected token 'new'
The correct way is either wrap route value parameters inside UrlHelper.Action
helper:
var url = '@Url.Action("ResultGrid", "User", new { xEdit = ViewData["Form"] })';
Or by using old-fashioned query string if the value passed from client-side variable:
var viewData = '@ViewData["Form"]';
var url = '@Url.Action("ResultGrid", "User")?xEdit=' + viewData;
Both ways produce URL as in example below (ViewData["Form"]
must be such like plain numeric or string value):
/User/ResultGrid?xEdit=someValue
Upvotes: 1