当用户点击某个链接时,我发生了一个事件,事件已经发生:
var dateParameter = "date=" + workday.DateString();
window.location.href = '@Url.Action("Index", "DateSelector")' + '?' + dateParameter;
我不想使用这种调用,因为我想在浏览器的URL中隐藏参数。
我该怎么做?有没有办法可以使用AJAX?
我在控制器中的方法看起来像这样:
public ActionResult Index(string date)
{
// some logic...
SomeViewModel vm = ...
return View(vm);
}
如果我使用AJAX,那么它就不会加载想要的页面。
答案 0 :(得分:0)
试试这个:
var dateParameter = "date=" + workday.DateString();
$.ajax({
url: '/DateSelector/Index/' + dateParameter,
type: 'POST',
datatype: "json",
contentType: "application/json; charset=utf-8"
});
希望有所帮助:)
答案 1 :(得分:0)
您也可以尝试以这种方式传递它:
window.location.href = '@Url.Action("Index", "DateSelector",
new { date = dateParameter })';
让我们稍微尝试一下代码:
var dateParameter = workday.DateString();
var text = "@Url.Action("Index", "DateSelector", new { date = "dateParameter" })"
text = text.replace("dateParameter", dateParameter);
window.location.href = text;