C# 使用MVC登录后如何路由到仪表板?
我有一个视图文件夹和login.cshtml,我想在用户登录后路由到我创建的仪表板。用户需要去哪个路由页面,有用的例子就足够了。换句话说,我希望当用户登录时,必须将它们重定向到我下面的索引.cshmtl(事件管理列表的仪表板)。请帮助队友,需要路由从一页到另一页。注册登录工作正常,只是我的登录必须路由到我的仪表板,以便用户查看事件列表C# 使用MVC登录后如何路由到仪表板?,c#,asp.net-mvc,C#,Asp.net Mvc,我有一个视图文件夹和login.cshtml,我想在用户登录后路由到我创建的仪表板。用户需要去哪个路由页面,有用的例子就足够了。换句话说,我希望当用户登录时,必须将它们重定向到我下面的索引.cshmtl(事件管理列表的仪表板)。请帮助队友,需要路由从一页到另一页。注册登录工作正常,只是我的登录必须路由到我的仪表板,以便用户查看事件列表 // RouteConfig.cs file routes.MapRoute( name:"Dashboard",
// RouteConfig.cs file
routes.MapRoute(
name:"Dashboard",
url:"{dashboard}/{action}/{id}",
defaults: new {controller = "Dashboard", action = "Index"}
);
// Views/Dashboard/Index.cshtml
@{
ViewBag.Title = "EventManagement List";
}
<hr/>
<hr/>
<hr/>
<h2>EventManagement List</h2>
<table id="EventManagementTable" class="ui celled table" style="width:100%">
@*Semantic UI*@
@*<table id="EventManagementTable" class="ui celled table">*@
@*Bootstrap*@
@*<table id="EventManagementTable" class="table table-striped table-bordered">*@
<thead>
<tr>
<th>TrainingID</th>
<th>TrainingType</th>
<th>TrainingDescription</th>
<th>Price</th>
<th>Venue</th>
<th>Facilitator</th>
<th>WhoAttend</th>
<th>RSVP</th>
</tr>
</thead>
<tfoot>
<tr>
<th>TrainingID</th>
<th>TrainingType</th>
<th>TrainingDescription</th>
<th>Price</th>
<th>Venue</th>
<th>Facilitator</th>
<th>WhoAttend</th>
<th>RSVP</th>
</tr>
</tfoot>
</table>
<!--Normal DataTables-->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.20/datatables.min.css" />
<!---JQuery ThemeRoller-->
<link href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/1.10.15/css/dataTables.jqueryui.min.css" rel="stylesheet" />
<!--Semantic UI-->
<link href="//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.6/semantic.min.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/1.10.15/css/dataTables.semanticui.min.css" rel="stylesheet" />
<!-- Bootstrap 4 -->
<link href="https://cdn.datatables.net/1.10.15/css/dataTables.bootstrap4.min.css" rel="stylesheet" />
@section scripts{
<script src="//cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/dataTables.jqueryui.min.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/dataTables.semanticui.min.js"></script>
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0.0-alpha.6/css/bootstrap.css" rel="stylesheet"/>
<script src="https://cdn.datatables.net/1.10.15/js/dataTables.bootstrap4.min.js"></script>
<script>
$(document).ready(function () {
$("#EventManagementTable").DataTable(
{
"ajax": {
"url": "/EventManagement/GetList",
"type": "POST",
"datatype": "json"
},
"columns": [
{ "data": "TrainingID" },
{ "data": "TrainingType" },
{ "data": "TrainingDescription" },
{ "data": "Price" },
{ "data": "Facilitator" },
{ "data": "WhoAttend" },
{"data":"RSVP"}
],
"serverSide": "true",
"order": [0, "asc"],
"processing": "true",
"language": {
"processing":"processing...... please wait"
}
});
});
</script>
}
// Views/Account/Login.cshtml
@model ContentManagementSystem.Models.LoginViewModel
@{
ViewBag.Title = "Login in";
}
<h2>@ViewBag.Title.</h2>
<div class="row">
<div class="col-md-8">
<section id="loginForm">
@using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h4>Use a local account to log in.</h4>
<hr />
@Html.ValidationSummary(true)
<div class="form-group">
@Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.UserName)
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.PasswordFor(m => m.Password, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Password)
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<div class="checkbox">
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Log in" class="btn btn-info" />
</div>
</div>
<p>
@Html.ActionLink("Register", "Register") if you don't have a local account.
</p>
}
</section>
</div>
<div class="col-md-4">
<section id="socialLoginForm">
@Html.Partial("_ExternalLoginListPartial", new { Action = "ExternalLogin", ReturnUrl = ViewBag.ReturnUrl })
</section>
</div>
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
-Must this first be created on RouteConfig.cs
e.g defaults: new{controller = "Account", action = "Index"}
//RouteConfig.cs文件
routes.MapRoute(
名称:“仪表板”,
url:“{dashboard}/{action}/{id}”,
默认值:新建{controller=“Dashboard”,action=“Index”}
);
//视图/Dashboard/Index.cshtml
@{
ViewBag.Title=“事件管理列表”;
}
事件管理列表
@*语义用户界面*@
@**@
@*引导*@
@**@
培训ID
训练类型
培训说明
价格
地点
促进者
参加
冒险类游戏
培训ID
训练类型
培训说明
价格
地点
促进者
参加
冒险类游戏
@节脚本{
$(文档).ready(函数(){
$(“#EventManagementTable”).DataTable(
{
“ajax”:{
“url”:“/EventManagement/GetList”,
“类型”:“职位”,
“数据类型”:“json”
},
“栏目”:[
{“数据”:“培训ID”},
{“数据”:“TrainingType”},
{“数据”:“培训说明”},
{“数据”:“价格”},
{“数据”:“调解人”},
{“数据”:“whoAttain”},
{“数据”:“RSVP”}
],
“服务器端”:“true”,
“订单”:[0,“asc”],
“处理”:“真”,
“语言”:{
“正在处理”:“正在处理……请稍候”
}
});
});
}
//Views/Account/Login.cshtml
@模型内容管理系统.Models.loginView模型
@{
ViewBag.Title=“登录”;
}
@ViewBag.Title。
@使用(Html.BeginForm(“Login”,“Account”,new{ReturnUrl=ViewBag.ReturnUrl},FormMethod.Post,new{@class=“form horizontal”,role=“form”}))
{
@Html.AntiForgeryToken()
使用本地帐户登录。
@Html.ValidationSummary(true)
@LabelFor(m=>m.UserName,新的{@class=“col-md-2控制标签”})
@TextBoxFor(m=>m.UserName,新的{@class=“form control”})
@Html.ValidationMessageFor(m=>m.UserName)
@LabelFor(m=>m.Password,新的{@class=“col-md-2控制标签”})
@Html.PasswordFor(m=>m.Password,新的{@class=“form control”})
@Html.ValidationMessageFor(m=>m.Password)
@CheckBoxFor(m=>m.RememberMe)
@LabelFor(m=>m.RememberMe)
@ActionLink(“注册”、“注册”),如果您没有本地帐户。
}
@Html.Partial(“_ExternalLoginListPartial”,new{Action=“ExternalLogin”,ReturnUrl=ViewBag.ReturnUrl})
@节脚本{
@Scripts.Render(“~/bundles/jqueryval”)
}
-必须首先在RouteConfig.cs上创建此文件吗
e、 g默认值:新建{controller=“Account”,action=“Index”}
public virtual ActionResult Index方法中的内容(…在帐户控制器上,验证登录后,您将从那里返回仪表板视图?@level\u zebra给我一个默认示例。