How to pass a textbox value from view to a controller in MVC 4?

后端 未结 5 1413
我在风中等你
我在风中等你 2021-02-13 23:56

Here i am fetching the value from database and showing it in a input field


and

5条回答
  •  鱼传尺愫
    2021-02-14 00:36

    I'll just try to answer the question but my examples very simple because I'm new at mvc. Hope this help somebody.

        [HttpPost]  ///This function is in my controller class
        public ActionResult Delete(string txtDelete)
        {
            int _id = Convert.ToInt32(txtDelete); // put your code           
        }
    

    This code is in my controller's cshtml

      >   @using (Html.BeginForm("Delete", "LibraryManagement"))
     {
    
    @Html.Label("Enter an ID number");
    @Html.TextBox("txtDelete")  }  
    

    Just make sure the textbox name and your controller's function input are the same name and type(string).This way, your function get the textbox input.

提交回复
热议问题