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.
50 lines
1.6 KiB
50 lines
1.6 KiB
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using System;
|
|
using System.Linq.Expressions;
|
|
|
|
namespace Infrastructure.Web
|
|
{
|
|
public class BaseController : Controller
|
|
{
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1054:URI 参数不应为字符串", Justification = "<挂起>")]
|
|
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");
|
|
}
|
|
|
|
public void SelectList<TResult>(Expression<Func<object, TResult>> expression, Func<MultiSelectList> selectListFunc, bool value = true)
|
|
{
|
|
if (expression is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(expression));
|
|
}
|
|
|
|
if (value)
|
|
{
|
|
var name = (expression.Body as MemberExpression).Member.Name;
|
|
SelectList(name, selectListFunc, true);
|
|
}
|
|
}
|
|
|
|
public void SelectList(string name, Func<MultiSelectList> selectListFunc, bool value = true)
|
|
{
|
|
if (selectListFunc is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(selectListFunc));
|
|
}
|
|
|
|
if (value)
|
|
{
|
|
ViewData[name] = selectListFunc();
|
|
}
|
|
}
|
|
}
|
|
} |