learning
learning

Reputation: 11725

2 forms in a single Razor view

I have 2 forms in my myPage.chtml page as follows:

@using (Html.BeginForm("Tests1", "Test", FormMethod.Post, new { id = "FormSearch1" }))
{ 
    <input type ="submit"  value="Filter1 " id="submit" />
}

and another form as follows:

@using (Html.BeginForm("Tests2", "Test", FormMethod.Post, new { id = "FormSearch2" }))
{ 
    <input type ="submit"  value="Filter2 " id="submit" />
}

However, I am having the error message and it`s not working upin clicking the submit buttons. What am I missing?

Warning 2 Another object on this page already uses ID 'submit'.

Upvotes: 1

Views: 2448

Answers (2)

Clyde Lobo
Clyde Lobo

Reputation: 9174

Simple

You have 2 <input> tags with the same id submit.

Upvotes: 0

hangy
hangy

Reputation: 10859

In your example, you have two <input> elements that have the same id="submit" attribute. id should be unique on each HTML page. To solve the problem, either remove the id attribute completely (if it is not actually used), or use different values.

If you need to have these submit buttons to have the same name but different values (considering the different Actions and ids submit in your example, I doubt that), you could try to use <input type="submit" value="Filter1" name="submit"/> and <input type="submit" value="Filter2" name="submit"/> instead.

Upvotes: 3

Related Questions