1

I have a razor page that uses T4template. Here is my razor code:

@model ResearchViewModel

<form method="POST" action=">

...

    @if (!Model.IsFinalized)
    {
        using (Html.BeginForm(MVC.Research.ActionNames.Reject, MVC.Research.Name, null, FormMethod.Post, new { @id = "RejectForm" }))
        {
            @Html.AntiForgeryToken()
            @Html.HiddenFor(model => model.Id)
        }
        using (Html.BeginForm(MVC.Research.ActionNames.Accept, MVC.Research.Name, null, FormMethod.Post, new { @id = "AcceptForm" }))
        {
            @Html.AntiForgeryToken()
            @Html.HiddenFor(model => model.Id)
        }
    }

    ...

</form>

The problem is that when the razor rendering this page, it cannot rendering first form !! I tried to change the sequence of these forms, and found that always the first form is not rendered. I Also tried to separate these forms using the partialview but the problem still exist. Does anyone knows that what's happening ?

2
  • 1
    Rather than creating multiple form tags, you can create single form with multiple different actions handled by submit buttons. Take a look for this example and this issue for implementation. Commented Nov 27, 2018 at 1:23
  • Just to add to the other comments, the ASP.NET way was to wrap the entire document in a <form /> tag. With Razor, you do not do it that way. If you need a single document with multiple forms, you can add each form as a distinct concern. Commented Nov 28, 2018 at 20:42

1 Answer 1

2

You are trying to nest multiple forms and you can't do that. See this link for an explanation: Can you nest html forms?

You need to remove your starting HTML

<form method="POST" action=">

because you can't have other forms inside them. I would guess that closing tag of your first form created by razor Html helper is closing this tag, so you can see the other form created by second razor Html helper

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.