Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C# MVC help

Posted on 2011-10-24
1
Medium Priority
?
224 Views
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

 <h2>Index</h2>
    <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
0
Comment
Question by:wademi
1 Comment
 
LVL 28

Accepted Solution

by:
strickdd earned 2000 total points
ID: 37019366
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.

[AcceptVerbs(HttpVerbs.Post)]
public View Index(string Search)
{
     //Do search, add to Model
     return View(); //pass model data here if necessary
}
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

810 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