假设我在MVC应用程序中有一个使用[Required]字段等注释的模型.
它在控制器中很好地调用ModelState.IsValid,但是我说我不在控制器中,并希望在模型上的应用程序的其他地方运行类似的检查.有可能以某种方式调用此功能吗?
class MyModel{
[Required]
public string Name{get;set;}
}
// Code elsewhere in app that isn't the controller
MyModel model = new MyModel();
//Can I run a modelstate.isvalid type check here on model? Would return false if Name wasn't set
Run Code Online (Sandbox Code Playgroud) 我试图在bootstrap 4中获得一个模态页脚,以获得多个100%宽度的行.因此,对于下面最基本的bootstrap模式示例,是否可以将Close和Save更改按钮设置在不同的行上,并且两者都是100%宽度?
<div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div><div class="modal-body">
...
</div><div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 我正在尝试在MVC4中指定一条路由,该路由会在显示特定操作名称的情况下忽略控制器名称。例如。
mysite.com/AnyControllerNameHere/SpecificAction-让我指定在使用时要使用的控制器和操作
mysite.com/AnyControllerNameHere/NotSpecificAction-将带我使用AnyControllerNameHere Controller和NotSpecificAction方法,例如MVC默认值。
我试图编写一些代码,但似乎没有达到我想要的效果。完整的路由配置只是MVC的默认值,而我尝试这样做是为了...
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"SpecificAction",
"{controller}/SpecificAction",
new { controller = "Home", action = "SpecificAction" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
Run Code Online (Sandbox Code Playgroud)