。我無法返回視圖()。請檢查下面的代碼。 這是Action。當我使用Request.IsAjaxRequest()時Request.IsAjaxRequest不會喚醒mvc
public ActionResult Index()
{
if (!Request.IsAjaxRequest()) {
return View("ajexview");
}
return view("About");
}
這個觀點
<script>
$(function() {
$("button").click(function() {
var car = { Make: 'Audi', Model: 'A4 Avant', Color: 'Black', Registered: 2013 };
$.ajax({
type: "POST",
url: "/home/index/",
data: car,
datatype: "html",
success: function (data) {
$('#result').html(data);
}
});
});
});
<button>Click me</button>
當我張貼有關視圖無法返回
您應該在控制器中使用其他操作來處理Ajax請求。通常,當你發出一個Ajax請求時,你將它指向一個返回類似'JsonResult'的動作。看看這個問題的控制器代碼:http://stackoverflow.com/questions/16186083/making-a-simple-ajax-call-to-controller-in-asp-net-mvc –