Answer the question
In order to leave comments, you need to log in
How to properly use input type="submit" in cshtml?
Hello, I'm doing a project on ASP.NET + MVC. Changed the style of some controls (textarea, text...) to roots using bootstrap. And then one problem arose: it does not pass data to the [HttpPost] method if it is not enclosed in the @using (Html.BeginForm()) {} block along with the necessary fields, but as soon as I enclose the controls necessary for sending data in this block, they lose their normal appearance. Is it possible to organize the data transfer in another way or use something instead of @using (Html.BeginForm()) {}?
Answer the question
In order to leave comments, you need to log in
The point is that standard helpers ( Html.BeginForm
etc.) don't by default assign classes to elements that are commonly used in Bootstrap. Therefore, each method has a version that accepts an anonymous object with attributes. For example, like this:
@Html.TextBoxFor(x => x.MyField, new { @class = "form-control" })
In principle, for simple models, we can use regular tags without html helpers. The main thing is to know the mapping rules and correctly fill in the name attribute of the desired control. For more ornate models or rendering through EditorTemplates, it's better to master all the input parameters of the helper methods.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question