You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/Infrastructure/Web/Mvc/BaseController.cs

41 lines
1.4 KiB

using Infrastructure.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Linq;
namespace Infrastructure.Web
{
public class BaseController : Controller
{
[ApiExplorerSettings(IgnoreApi = true)]
public IActionResult RedirectTo(string action = "Index", string controller = null, string rawMesage = "操作成功", object routeValues = null, string returnUrl = null)
{
if (returnUrl is null)
{
returnUrl = Url.Action(action, controller, routeValues);
}
ViewBag.Message = rawMesage;
ViewBag.Url = returnUrl;
return View("Redirect");
}
protected IActionResult Result<TEditModel>(object model)
{
if (this.IsJsonRequest())
{
return Json(new
{
schema = this.GetJsonSchema<TEditModel>(),
model,
errors = ModelState.Where(o => o.Value.ValidationState == ModelValidationState.Invalid),
data = ViewData
}, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver(), ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
}
return View(model);
}
}
}