Does ASP.NET MVC start form somewhat?

Hi, I am using several forms of start. I'm not sure this is a good idea. This is my code.
<% using (Html.BeginForm("TagManagement", "InternalTag",FormMethod.Post))
   {%>
   <%: Html.AntiForgeryToken() %>

    <table>         
        <tr>
            <td><%:Html.Label("Type") %></td>
            <td style="text-align:left"><%:Html.DropDownList("ObjectType",ViewData["TagObjects"] as IEnumerable<SelectListItem>)%></td>
        </tr>
        <tr>
            <td><%:Html.Label("Search ID")%></td>
            <td style="text-align:left"><%:Html.TextBox("ObjectID2")%></td>
        </tr>
        <tr>
            <td></td>
            <td><input id="Search" type="submit" value="Search" />&nbsp;&nbsp;&nbsp;<input id="Create" type="button" value="Add to New Tag" onclick="AddTagElements()" /></td>
        </tr>
    </table>
    <br />

<% } %>

<% using (Html.BeginForm("CreateTag","InternalTag",FormMethod.Post)) { %>
<%: Html.AntiForgeryToken() %>
<div id="AddTag">
      <input id='SaveTag' type='submit' value='Save' style='width: 125px' />
</div>
<% } %>

routing code

"Tags/{controller}/{action}/{id}/{type}",
new { action = "Index", id = UrlParameter.Optional, type = UrlParameter.Optional }

my controller methods:

public ActionResult TagManagement(FormCollection FC,Guid? ID,InternalTagRef_Types? Type)
public ActionResult CreateTag(FormCollection FC, Guid ID, InternalTagRef_Types Type)

when i click on search. TagManagement Actions parameters are populated correctly. When I click on SaveTag, it tries to call the CreateTag action, but cannot, because the identifier and type are missing. I get an error. The parameter dictionary contains a null entry for the "ID" parameter of a non-nullable type of "System.Guid". It should get these values ​​from the URL, i.e. http: // localhost: 1338 / Tags / InternalTag / TagManagement / D104EBF5-470B-4FAA-9FC7-5391922CCE94 / Projects , like TagManagement. Please, help.

+3
2

( ), , , , . , .


UPDATE:

:

<% using (Html.BeginForm(
        "CreateTag", "InternalTag", 
        new { id = RouteData.Values["id"], type = RouteData.Values["type"] }, 
        FormMethod.Post)) { %>
    <%: Html.AntiForgeryToken() %>
    <div id="AddTag">
        <input id='SaveTag' type='submit' value='Save' style='width: 125px' />
    </div>
<% } %>
+3

, , . -,

<input id="Create" type="button" value="Add to New Tag" onclick="AddTagElements()" />

javascript AddTagElements ().

<% using (Html.BeginForm("CreateTag","InternalTag",FormMethod.Post)){%>
    <%: Html.AntiForgeryToken() %>
    <div id="AddTag">
        <input id="tags" type="hidden" value=""/>
        <input id='SaveTag' type='submit' value='Save' style='width: 125px' />
    </div>
<%}%>
+1

Source: https://habr.com/ru/post/1780183/


All Articles