Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Auxiliary methods in MVC3

Shulou Source: shulou.com Published: 2022-06-03 02:44:45 09月21日 Update

This article mainly introduces how to use the auxiliary methods in MVC3, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand.

one,

@ Html.TextBox ("txt", "hello", new {style = "width:1000px;height:1000px;"})

Generate tags:

two,

Special properties (class:c# reserved keywords)

@ Html.TextBox ("txt", "hello", new {style = "width:1000px;height:1000px;", @ class= "aa"})

Generate tags:

three,

Attributes with concatenated characters (for example: data_result)

@ Html.TextArea ("text", "hello", new {data_result = "data"})

Generate tags:

Hello

four,

@ using (Html.BeginForm ()) {}

Generate tags:

= add input element

-@ Html.TextBox

@ Html.TextBox ("Title", string.Empty) / / single-line input

Generate tags:

-@ Html.TextArea

@ Html.TextArea ("Title", string.Empty) / / Multi-line input

Generate tags:

-@ Html.Label

Html.Label ("Title", "Please enter:")

Generate tags:

Please enter:

-@ Html.DropDownList

Controller code:

Public ActionResult Create2 () {/ / radio collection, value field, text field, selected value ViewBag.Genre = new SelectList (db.Genres, "GenreId", "Name", 1); return View ();}

View code:

@ Html.DropDownList ("Genre", string.Empty)

-@ Html.ListBox (multiple choices are available)

@ {List listbox = new List (); listbox.Add ("a"); listbox.Add ("b"); listbox.Add ("c");} @ Html.ListBox ("listitem", new SelectList (listbox, "a"))

Controller code:

/ / public ActionResult Create2 () {/ / Radio collection, value field, text field, selected value ViewBag.Genre = new SelectList (db.Genres, "GenreId", "Name", 1); / / multiple selection ViewBag.Genre2 = new MultiSelectList (db.Genres, "GenreId", "Name", new List () {"1", "2"}); return View ();}

View code:

@ Html.ListBox ("Genre") @ Html.ListBox ("Genre2")

-@ Html.ValidationMessage ()

Controller code:

Public ActionResult Create3 () {return View ();} [HttpPost] public ActionResult Create3 (string text) {if (string.IsNullOrEmpty (text)) {ModelState.AddModelError ("text", "error"); return View () } else {return RedirectToAction ("Index");}}

View code:

@ {ViewBag.Title = "Create3";} Create3@using (Html.BeginForm ()) {@ Html.TextBox ("text") @ Html.ValidationMessage ("text")}

Thank you for reading this article carefully. I hope the article "how to use Auxiliary methods in MVC3" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Tags generation code input fields articles controllers views controls methods auxiliaries attributes text special value elements keywords keywords interests and Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Linux Apple Shulou Technology Shulou Tech Info