我正在尝试通过jQuery $ .post调用控制器,但是我的控制器方法的参数不断获得NULL值,尽管它似乎设置类似于其他控制器方法。
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SearchWeatherLocations(string searchFor)
{
//Do Some Magic
}
routes.MapRoute("SearchWeatherLocations", "Home/SearchWeatherLocations/{searchFor}",
new
{
controller = "Home",
action = "SearchWeatherLocations"
});
<script type="text/javascript" language="javascript">
$(document).ready(function () {
GetWeatherLocations("seat");
});
function GetWeatherLocations(sSearchFor) {
var divToBeWorkedOn = '#locations';
var webMethod = '<%= Url.Action("SearchWeatherLocations", "Home") %>/';
var url = webMethod + sSearchFor;
$.post(url, function (data) {
$('#locations').children().remove();
for (var count in data) {
$('#locations').append("<li>" + data[count].LocationName + " (" + data[count].LocationCode + ")</li>");
}
});
}
</script>
答案 0 :(得分:1)
试试这样的帖子;
的jQuery
$.post("/Articles/jQueryAddComment", { commentText: commentText, id: id, type: commentType }, function(newCommentListHTML)
{
});
控制器
public ActionResult jQueryAddComment(string commentText, int id, string type)
{
}