C# ASP.NET MVC Forms Creating a Basic Form Using HTML Helpers

beginform method

whats the syntax to beginform within using statement

Report.cshtml
@{
    ViewBag.Title = "Report an Issue";
}

<h2>@ViewBag.Title</h2>
@using(@HTML.BeginForm)
{

<div>
        <label for="Name">Name</label>
        <input type="text" id="Name" name="Name" />
    </div>

    <div>
        <label for="Email">Email</label>
        <input type="text" id="Email" name="Email" />
    </div>

    <div>
        <label for="DepartmentId">Department</label>
        <input type="text" id="DepartmentId" name="DepartmentId" />
    </div>

    <div>
        <label for="Severity">Severity</label>
        <input type="text" id="Severity" name="Severity" />
    </div>

    <div>
        <label for="Reproducible">Reproducible</label>
        <input type="text" id="Reproducible" name="Reproducible" />
    </div>

    <div>
        <label for="DescriptionOfProblem">Description of Problem</label>
        <textarea id="DescriptionOfProblem" name="DescriptionOfProblem"></textarea>
    </div>

    <button type="submit">Save</button>

}

2 Answers

Steven Parker
Steven Parker
203,729 Points

You're close, but:

  • C# is case sensitive, and you typed "HTML.BeginForm" instead of "Html.BeginForm"
  • when you call a function, you must put parentheses after the function name, even if it takes no parameters
  • you don't need to use the "@" symbol twice ... the first one is effective for the entire line

Thank you.