Bug tracker: Create the BugForm view
After you create the
BugModel class, you create the BugForm view. The BugForm view represents a form that is used by the user to log a new bug. To create the BugForm view:
- In Visual Studio, navigate to the Areas » BugTracker » Views » Bug folder, create a new file with the cshtml extension.
Name the file BugForm.
- Add using statements to the following namespaces:
- Set the layout of the view.
Use the BugTrackerLyout view as the layout.
- Define a form:
- Use the BeginForm method of the HtmlHelper object.
- Specify the action, controller and the route values. The form navigates to the specified URL after it is submitted.
- Specify the method of the form to be FormMethod.Post.
Note that you have to put the call to the BeginForm method inside a using clause.
- Define the input fields:
- Inside the using clause for the BeginForm method, create a fieldset element.
- Inside the element define the input fields for the bug details.
When defining the choice fields, set their values to the same values as the one defined for the Bug content type in the custom module. Note that the names of the input fields must be the same as the names of the properties of the BugModel class.
GITHUB EXAMPLE: For more information about the content of the file, see the BugForm.cshtml file of the downloaded sample project.