Search code examples
asp.net-mvc-3findcontrol

MVC3 Finding a control by its Name


I have a C#.Net web app and I am trying to access one of the HTML/ASP Text Boxes in the Controller for the Edit View of my Proposal model. In a non-MVC app, I was able to do this using Control.ControlCollection.Find(). Is there an equivalent for a MVC3 project?


Solution

  • You ask for an equivalent of Control.ControlCollection.Find() in MVC?

    In MVC your controller is not aware of controls.

    The controller just receives data via parameters and returns data via the function result.

    What do you want to do with the control in your controller code?

    If you want to access the value, you should bind it to a parameter:

    View:

    <input name="MyControl" type="text" />
    

    Controller:

    public ActionResult MyAction(string MyControl) {
        // MyControl contains the value of the input with name MyControl
    }