In this article i will show you how you can access or get the textbox or textbox for value in asp.net core 6 / mvc application at controller end using c#.net. So in this article first we will check how we can access the TetBox control value at controller end.
TextBox:
At controller end first we will index action method, and create a view. In this view we will add the below code.
@{ ViewData["Title"] = "Home Page"; } @using
(Html.BeginForm("Index", "Home",
FormMethod.Post, new { @id = "formxmldata", @enctype = "multipart/form-data" })) { <b>Get TextBox Value </b> <span style="color:red">@ViewBag.Data</span> <br /> @Html.TextBox("empname", "", new { @class = "form-control", @placeholder = "Please enter employee
name" }) <br /> <input type="submit" value="Submit" /> } |
Now we will add the below code at controller end.
[HttpGet] public
IActionResult Index() { return View(); } [HttpPost] public
IActionResult Index(string empname) { ViewBag.Data = empname; return View(); } |
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Project.Models { public class EmpNameModel { public string EmpName { get; set; } } } |
@model Project.Models.EmpNameModel @{ ViewData["Title"] = "Home Page"; } @using
(Html.BeginForm("Index", "Home",
FormMethod.Post, new { @id = "formxmldata", @enctype = "multipart/form-data" })) { <b>Get TextBox Value </b> <br /> <span style="color:red">@ViewBag.Data</span> <br /> @Html.TextBoxFor(m => m.EmpName, "", new {
@class = "form-control", @placeholder = "Please enter employee
name" }) <br /> <input type="submit" value="Submit" /> } |
[HttpGet] public
IActionResult Index() { return View(); } [HttpPost] public
IActionResult Index(EmpNameModel empNameModel) { ViewBag.Data =
empNameModel.EmpName; return View(); } |
0 comments:
Please let me know your view