Sina Soltani
Sina Soltani

Reputation: 13

Razor not rendering multiple Html.BeginForm()

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 ?

Upvotes: 1

Views: 369

Answers (1)

adolja
adolja

Reputation: 189

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

Upvotes: 2

Related Questions