How to activate another form if boolean is true otherwise saved the data

Viewed 38

I was given a task to prepare for a technical exam and this is the Requirement. I am confused and just wanted to get some thoughts if if the code below met this requirement.

a.)"create web application 2 user role login

b.)create web application with 1 dashboard + 2 forms entry (form a & form b, form b is subform of form a)

c.)allow user enter entry in form a, make a boolean in form a. if Boolean = true activate form b for user input, else user can submit form a only. Dashboard display list of form a."

Here's what I have came up:

@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>

1 Answers

In your form1 View include a checkbox like

<input type="checkbox" value="1" name="Proceed"> Proceed Form B

In the Controller for Form 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
};
  
Related