我的任務是準備技術考試,這是要求。如果下面的代碼滿足此要求,我很困惑,只是想了解一下。
a.)"創建 web 應用程式 2 用戶角色登錄
b.) 使用 1 個儀表板 2 個表單條目創建 Web 應用程式(表單 a 和表單 b,表單 b 是表單 a 的子表單)
c.) 允許用戶在表單 a 中輸入條目,在表單 a 中創建一個布林值。如果 Boolean = true 為用戶輸入激活表單 b,否則用戶只能提交表單 a。表格a的儀表板顯示串列。”
這是我想出的:
@page
@model IndexModel
@using Microsoft.AspNetCore.Identity;
@inject SignInManager<IdentityUser> SignInManager
<div class="container mt-5" id="formA">
<div class="row justify-content-center align-items-center">
<div class="col-sm-12 col-md-12 col-lg-4">
<h1 class="mb-3">Form A</h1>
<form method="post">
@if (SignInManager.IsSignedIn(User) && User.IsInRole("Admin"))
{
bool bolAdmin = true;
<div class="mb-3">
<label class="form-label"> First Name</label>
<input type="text" class="form-control" />
</div>
if (bolAdmin == true)
{
<div class="mb-3">
<label class="form-label"> Gender</label>
<input type="text" class="form-control" />
</div>
<div class="mb-3">
<button type="submit" class="btn btn-primary">Activate</button>
</div>
}
else
{
<div class="mb-3">
<button type="submit" class="btn btn-primary">Save</button>
</div>
}
}
</form>
</div>
</div>
</div>
uj5u.com熱心網友回復:
在您的 form1 視圖中包含一個復選框,例如
<input type="checkbox" value="1" name="Proceed"> Proceed Form B
在表格 A 的控制器中
public ActionResult FormA(yourModel Model, string Proceed)
{
// your save procedure
if (Proceed == "1")
{
Return RedirectToAction("FormB",new{Id = Model.Id});
}
else
{
Return RedirectToAction("Index");
}
}
public ActionResult FormB(int Id)
{
//You may pass the form A Id here to Form B reference
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/508228.html
標籤:网 asp.net-mvc asp.net 核心 剃刀页面