Solved

C# MVC4 views - including a search page

Posted on 2013-01-08
6
169 Views
Last Modified: 2013-01-22
VS2012, c#

I apologize, I've been doing desktop apps with C# and haven't given web apps much of a thought until now so I'm learning and very much green.  I'm not sure of the terminology I need to search on so sorry for the simple question.

I've got a basic site in development with a model, view, and controller that functions.  Now, instead of the view dumping all the lines from the DB I want to add a search functionality into it.  Do I create the search boxes in the view or do I create another view and link it into the current view?  If the latter is the case, how do I link the external view into the current one?

Thanks for your help!
0
Comment
Question by:sej69
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38759996
The correct choice really depends on you.  How would you like it to function?  I have a page with a search box in a partial view that is rendered on the _Layout.cshtml page.
0
 

Author Comment

by:sej69
ID: 38760494
So the term I need to search on is "partial view".  I'll dig into that; thanks.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 38760985
I found the _SearchPartial page:

 using (Html.BeginForm("SearchResults", "Shared"))
    { 
        <div class="searchContainer">
            @(this.Select("searchOption")
                .Class("sltSearch")
                .Options(@Model.Header.CustomerSearchOptionList)
              )
            <input name="searchCriteria" type="text" class="fldSearch" />
            @(this.SubmitButton("")
                .Class("btnSearch")
             )
        </div>
    }

Open in new window


When the page posts back, there is a SearchResults method on the SharedController.
0
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 

Author Comment

by:sej69
ID: 38761715
LearnedOne, is that custom coded or is that code generated for you?  I have a lot of files that were pre-generated but nothing called shared...
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38762873
What controllers do you have?  That is a class that I created myself.  The decision on my side was to have a single controller called Shared.  You would just need the Action method and the Controller as arguments for the Html.BeginForm (Action, Controller).
0
 

Author Closing Comment

by:sej69
ID: 38805523
Led me down the right path to solve my problem. Thanks!
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

749 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