开发者

ASP.MVC ValidationSummary on success

开发者 https://www.devze.com 2023-01-08 07:21 出处:网络
ValidationSummary can easly display error messages开发者_StackOverflow. But how can I make it a success message I return from my action.

ValidationSummary can easly display error messages开发者_StackOverflow.

But how can I make it a success message I return from my action.

I am calling this action within Ajax request.

Any idea?


As you've discovered ValidationSummary is for displaying error messages. If you are using AJAX you could have your action return messages in JSON:

[HttpPost]
public ActionResult Foo()
{
     // Do something
     return Json(new { message = "success" });
}

And then call it:

$.post('/home/foo', { }, function(json) {
    alert(json.message);
});


Ideally, I want to do something like this

ModelState.AddModelError("SUCCESS", mySuccessMessage);

I'm thinking about modifing the CSS of ValidationSummary to display the message in green color.

but I don't know where this CSS is located

0

精彩评论

暂无评论...
验证码 换一张
取 消