Form not redirecting to the action in cshtml

I have a .cshtml file that shows a page of my application. In the application, there is a top menu where there are different buttons. The Code is:-

<div id="top_menu">
    <form action="@Url.Action("Pause", new { sessionId = Model, schoolId = ViewData["SchoolId"] })" method="post">
        <button type="submit">Pause</button>
    </form>

    <button id="score_button" type="button" class="text-group">
        <span>Score:</span>
        <span style="font-size: 1.5em" data-bind="text: score"></span>
    </button>

    <span id="elapsed_time" class="text-group">
        <span>Time elapsed:</span>
        <span style="font-size: 1.5em" data-bind="text: time"></span>
    </span>

    <button type="button" onclick="SR.ERSIM.showInfo('info_resources')">
        <i class="fas fa-check"></i> Resources
    </button>

    <form action="@Url.Action("Instructions")" method="get" target="_blank">
        <button type="submit">
            <i class="far fa-life-ring"></i> Help
        </button>
    </form>
</div>

Now every other thing works fine but the last button “Help” should redirect to the Instructions action of the Controller but it always redirects to the Index Action of the Controller. I cannot figure out this issue. How can I Redirect to the Instructions action?

My Controller Code for it:-

[Route("Schools/{schoolId:int}/VC/EmergencyRoom")]
public EmergencyRoomController(IEmergencyRoomRepository emergencyRoomRepository,
    EmergencyRoomService emergencyRoomService, ISessionRepository sessionRepository)
{
    this.emergencyRoomRepository = emergencyRoomRepository;
    this.emergencyRoomService = emergencyRoomService;
    this.sessionRepository = sessionRepository;
}

[HttpGet("{sessionId:long}")]
[ResponseCache(NoStore = true)]
public async Task<IActionResult> Index(long sessionId, int schoolId)
{
    Sessions session = await this.sessionRepository.GetSessionAsync(sessionId, 
        this.User.GetUserId());
    if (session == null)
    {
        return NotFound();
    }
   
    ViewData["SchoolId"] = schoolId;
    return this.View(session.Id);
}

[HttpGet("Instructions")]
[AllowAnonymous]
public ViewResult Instructions()
{
    return this.View();
}

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Change the Help form like this:

<form action="Instructions" method="get" target="_blank">
    <button type="submit">
        <i class="far fa-life-ring"></i> Help
    </button>
</form>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x