C# MVC help

Posted on 2011-10-24
Last Modified: 2013-12-16
I am new to MVC and needs some help. I created a simple website(C#,visual studios 2010) program that query my database and return results on a web page. This works perfectly fine. I added a search text box and a button to my site to facilitate searching. I added the following to the Views -> Sites -> index.aspx

    <label for="Search server">Search:</label>
<%= Html.TextBox("Search") %>
   <button class="okButton" type="submit" value="Search" >Search</button>

So my text box and button displays fine.

I figured I would enter code to implement the search text box and button in the Controller. Is that correct?
I am not sure how to refer to those buttons since I just added them to the Index.aspx.

Can somone give me and example of how and where to implement the search text box plus button fucntionality?

Please see the attached screenshot Screenshot
Question by:wademi
    1 Comment
    LVL 28

    Accepted Solution

    With MVC you don't reference the controls like you do in ASP.Net webforms. You need to create a controller that accepts a parameter that is the same name as your search textbox.

    public View Index(string Search)
         //Do search, add to Model
         return View(); //pass model data here if necessary

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now