[英]Variables contain values but in action they equals NULL
我有以下js代碼:
$("#dateRange").change(function() {
var date = $(this).attr("value");
var test = "1";
var eventId = $("div.movie").attr("eventid");
$("#scheduleList").load("/EventSchedule/GetSchedule/?date=" + date + "&dayRange=" + test + "&eventId=" + eventId);
});
這是動作:
public EmptyResult GetSchedule(string date, string dayRange, string eventId)
{
// some code
}
在螢火蟲中,所有變量均正確填充: date
包含date, test
包含1
, eventId
包含12
。 但是,在控制器操作中, dayRange
和evendId
等於null
。 date
參數已填寫。
問題在哪里?
更新: div.movie:
<div class="movie" eventid="12" type="Film">
<div class="poster">
<img src="/Image/GetImage">
<div class="btn_buy_ticket">
<div>
<i></i>
<span>
<a href="#">Купить билет</a>
</span>
<em></em>
</div>
</div>
</div>
</div>
我的路線:
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
var entryRoute = new PageEntry("page/{name}/",
new RouteValueDictionary(
new
{
controller = "DynamicPage",
action = "Index",
name = string.Empty
}),
new RouteValueDictionary(new { name = @".+" }),
new MvcRouteHandler());
routes.Add("display-page",
entryRoute);
routes.MapRoute(
"Activate",
"Account/Activate/{username}/{key}",
new
{
controller = "Account",
action = "Activate",
username = UrlParameter.Optional,
key = UrlParameter.Optional
});
}
謝謝。
可能是某些參數包含空格。
檢查導致我前天遇到同樣問題的原因。
對於dayRange
您可能需要使用$("#selectdayRange").text()
您可能還需要encodeURIComponent($("#selectdayRange").text());
為了能夠插入查詢參數。
嘗試刪除/
$("#scheduleList").load("/EventSchedule/GetSchedule?date=" + date ...
如果您從來沒有擺弄過Global.asax文件,則默認情況下,URL路由到{controller}/{action}/{id}
。
但我建議使用ViewModel來傳遞數據,因為您正在使用MVC。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.