Asp.net core 如何执行API,然后重定向到项目中的其他页面?

Asp.net core 如何执行API,然后重定向到项目中的其他页面?,asp.net-core,Asp.net Core,我陷入了一个问题,每当我提交时,它都会进入一个空白页来执行api。 我想,它应该执行API,然后重定向到另一个页面。 我怎么能做到呢, 下面是我的cshtml代码 @model CourseGamePlay.Dtos.StudentsDTO @{ ViewBag.Title = "Admin Panel - Weeks"; Layout = "~/Views/Shared/_adminLayout.cshtml"; } <h2>LOGIN&l

我陷入了一个问题,每当我提交时,它都会进入一个空白页来执行api。 我想,它应该执行API,然后重定向到另一个页面。 我怎么能做到呢, 下面是我的cshtml代码

@model CourseGamePlay.Dtos.StudentsDTO
@{
ViewBag.Title = "Admin Panel - Weeks";
Layout = "~/Views/Shared/_adminLayout.cshtml";
}

<h2>LOGIN</h2>
<body>
<form method="post" action="/api/studentlogin">
<div class="form-horizontal">
<div class="form-group">
@Html.LabelFor(s => s.name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-4">
@Html.EditorFor(s => s.name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(s => s.name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-15">
<input type="submit" value="Login" class="btn btn-primary"/>
</div>
</div>
</div>
</form>
</body>
@* <script>
$(function(){
$("#redirect").click(function (e) {
e.preventDefault();
document.location = '@Url.Action("Week","Home")';
});
});
</script> *@
@model CourseGamePlay.Dtos.studentsdo
@{
ViewBag.Title=“管理面板-周”;
Layout=“~/Views/Shared/_adminLayout.cshtml”;
}
登录
@LabelFor(s=>s.name,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(s=>s.name,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(s=>s.name,“,new{@class=“text danger”})
@* 
$(函数(){
$(“#重定向”)。单击(函数(e){
e、 预防默认值();
document.location='@Url.Action(“周”、“家”);
});
});
*@

您可以使用ajax发送请求,并在回调函数中执行重定向。