Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 340463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:37:06+00:00 2026-05-12T10:37:06+00:00

How do I retrieve the value of a textbox in asp.net mvc to store

  • 0

How do I retrieve the value of a textbox in asp.net mvc to store the value on to some variable?

I have a textbox like this <%=Html.TextBox("testbox") %> on the index view page.

I have a button like this <input type="submit" />

I’m using the default view page which comes when you open a new mvc app.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:37:07+00:00Added an answer on May 12, 2026 at 10:37 am

    In your controller;

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Search(FormCollection collection)
    {
      String g = collection["textFieldname"]
    }
    

    or you could use;

    TryUpdateModel(modelName);
    

    The above is the prefered solution. If you need more info on TryUpdateModel then post a comment and I’ll flesh it out for you.

    EDIT:

    Rather than explain it let me simply show you;

    In your controller:

    public class MyFormViewModel
    {
      public string myInput {get; set;}
    }
    
    public ActionResult Search()
    {
      MyFormViewModel fvm = new MyFormViewModel();
      return View(fvm);
    }
    
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Search(FormCollection collection)
    {
      MyFormViewModel fvm = new MyFormViewModel();
      TryUpdateModel<MyFormViewModel>(fvm);
    
      string userInput = fvm.myInput;
    }
    

    Then in your view;

    <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<YOURNAMESPACE.Controllers.MyFormViewModel>" %>
    
    <%= Html.TextBox("myInput", Model.myInput) %>
    

    Notice two things.

    The page is inheriting from your model/class defined in the controller. Not the best place for it but as an example it’ll do.

    The other thing is that the text box is name the same as the property in the model. In this case myInput.

    When the controller does UpdateModel it’ll reflection the thing out and match up the textbox name with the name of the field within your form view model.

    Make sense?

    EDIT 2

    Also don’t forget to wrap the button and your field in a;

    <% using (Html.BeginForm()) {%>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic form with some ASP.NET textbox fields laid out and I
I have an ASP.NET page where I am dynamically building LinkButton and TextBox elements.
I have an existing ASP.NET MVC 2 application that I've been asked to extend.
this is my xml file,i do not known how to retrieve value from xml
I have next problem, when I'm trying to retrieve value from xforms:select elements I
I need to retrieve a value from a website (can vary and I have
Alright guys, Need some help! Im working with asp.net mvc3 razor (and am fairly
I would like to know how to retrieve the value of a textarea box
ASP.NET 1.1 - I have a DataGrid on an ASPX page that is databound
I have a disabled TextBox that I am editing the value of on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.