için kullanmak: Index.cshtml itibarenSağ yolu ben MVC4 uygulama yapısı şu var ajax
i SomeActionMethod() için ajax arama yapmaya çalışıyorum, yer benim
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="Scripts/jquery-2.2.2.min.js"></script>
</head>
<body>
<script>
$.ajax({
url: '@Url.Action("SomeActionMethod", "HomeController")',
type: "POST",
cache: false,
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function (data) {
alert(data);
},
error: function() {
alert("fail");
}
});
</script>
</body>
</html>
HomeController.cs: gibi HomeController.cs
yolu veya denetleyici nesi var:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace SapRepLanciatoreCAS.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
//trying to invoke from ajax
[HttpPost]
public ActionResult SomeActionMethod()
{
return Json(new { foo = "bar", baz = "Blech" });
}
}
}
0 Ben bu hata var başvurumu başlattığınızda?
Dostum! Haklısın! Ben bu sorun üzerine bir gün geçirdim ... –
Bu sinir bozucu olduğunu biliyorum, Resharper gibi araçları deneyin ve bu gibi görüntüleme hataları gösterir;) – Zaki
ASP.NET MVC Bu desen bana hata veriyor. – Graham