admin管理员组文章数量:1302968
I'm trying to figure out the best way to do it and have seen a lot of suggestions, but can't get anything to work quite right and would rather do it the best way first.
Here's the ActionResult on the Controller:
public ActionResult Details(string selectedArtist)
{
//other code
return View(selectedArtist)
}
Here's the javascript on the client:
$('#results').on('click', '.item', function () {
var selectedArtist = $(this).data('artistInfo');
var selectedId = encodeURIComponent('ARE602H1187FB3B8F8')
var url = '@Url.Action("Details", "Artist", new { id = "__id__" })';
window.location.href = url.replace('__id__', selectedId);
})
Ideally, I would like the pass the selectedArtist object to the controller. It's basically a javascript class that matches a Artist model I have. For now though as a test I am just trying to pass an Id as a string to the controller and can't get it to, it just always es up as NULL.
The request that it's building looks pretty good to me ".../Artist/Details/ARE602H1187FB3B8F". However, I'm debugging and the parameter on the controller always ends up NULL.
Am I missing something? And/or is there a better way to do this? Thanks in advance.
I'm trying to figure out the best way to do it and have seen a lot of suggestions, but can't get anything to work quite right and would rather do it the best way first.
Here's the ActionResult on the Controller:
public ActionResult Details(string selectedArtist)
{
//other code
return View(selectedArtist)
}
Here's the javascript on the client:
$('#results').on('click', '.item', function () {
var selectedArtist = $(this).data('artistInfo');
var selectedId = encodeURIComponent('ARE602H1187FB3B8F8')
var url = '@Url.Action("Details", "Artist", new { id = "__id__" })';
window.location.href = url.replace('__id__', selectedId);
})
Ideally, I would like the pass the selectedArtist object to the controller. It's basically a javascript class that matches a Artist model I have. For now though as a test I am just trying to pass an Id as a string to the controller and can't get it to, it just always es up as NULL.
The request that it's building looks pretty good to me ".../Artist/Details/ARE602H1187FB3B8F". However, I'm debugging and the parameter on the controller always ends up NULL.
Am I missing something? And/or is there a better way to do this? Thanks in advance.
Share Improve this question asked Feb 5, 2014 at 3:38 mrshickadancemrshickadance 1,2514 gold badges20 silver badges34 bronze badges1 Answer
Reset to default 5Two options. Update your route table to properly allow the route with its slug "ARE602H1187FB3B8F" to be routed to the applicable action method. Or, you could pass id
as a query string parameter, thereby using the default route in your route table:
... Artist/Details?selectedArtist=ARE602H1187FB3B8F
本文标签: javascriptPass parameter with windowlocationhref to MVC ActionResultStack Overflow
版权声明:本文标题:javascript - Pass parameter with window.location.href to MVC ActionResult - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741716853a2394163.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论