在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
function save() { var data = { 'Name': $('#name').val(), 'Age': $('#age').val() }; $.ajax({ url: '/user/Detail', //'@Url.Action("Detail", "user")', data: JSON.stringify(data), type: 'POST', contentType: 'application/json', //'application/json; charset=utf-8', dataType: 'json', success: function (result) { // } }); }
public class UserController : Controller{ public ActionResult Detail(string Name, string Age){ User user = new Usr(); user.Name = Name; user.Age = Age; return View("Detail", user); } }
[MyAttribute(Message="TestJson")] public ActionResult Detail(){....} public class MyAttribute : FilterAttribute, IActionFilter { public string Message { get; set; } public void OnActionExecuting(ActionExecutingContext filterContext) // before executing the method { filterContext.Controller.ValueProvider.GetValue("Name").AttemptedValue; filterContext.HttpContext.Response.Write( string.Format("[Before Action: {0}]", Message)); } public void OnActionExecuted(ActionExecutedContext filterContext) // after executed the method { filterContext.HttpContext.Response.Write( string.Format("[After Action: {0}]", Message)); } }
$.ajax({ url: '/user/Detail', data: {name: 'Tom'}, // have a test by enclosing name with single quote if test failed. type: 'POST', success: function (result) { alert(result); }, error: function (xhRequest, text, thrownError) { alert(xhRequest); } }); |
请发表评论