开发者

Is this project doable in ASP.NET MVC?

I am new to Stack Overflow and to ASP.NET MVC.

I have been asked to do a project where I want to use ASP.NET MVC, but I have som开发者_运维问答e problems wrapping my head around it and I hope some of you could get me in the right direction.

The project is a kind of a search portal. On every page there is a dropdown box where you basicly select the dataset (it's based on books) you want to search. In the dropdown is the name of the book you want to search.

Of course there is also a search field. These 2 objects are on every page and has the same function on all pages, and I can't get these 2 objects to communicate.

I have these 2 in separate partialviews and want to generate an action for the search formfield something like this:

domain.com/{bookname}/search/{searchterm}: this is the thing created from the dropdown and the search box.

But can I do this in the searchfields partialview in some way, or do I have to grab these value in each controller?

I hope this makes any sense.


Create a partial view with your dropdown and textbox, using the BeginForm helper:

<% using(Html.BeginForm("Index", "Search")) %>
<% { %>
    <%= Html.DropDownList("BookNames") %>
    <%= Html.TextBox("SearchTerm") %>
<% } %>

Then in your SearchController's Index action, you should be able to grab the values from the form collection or using your dropdown's and textbox's id.

public ActionResult Index(FormCollection frmCollection)
{
  // ...
  // also you can redirect to another action/controller if you needed
  // return RedirectToAction("...", "...");
}

or

public ActionResult Index(int bookNames, string searchTerm)
{
  // ...
  // also you can redirect to another action/controller if you needed
  // return RedirectToAction("...", "...");
}

Hope this helps.


I have implemented a similar search requirement on one of my projects with ASP.NET MVC. However, I had the Dropdown and Search in a single Partial View.

I then used Javascript to pick up the selected values and redirect the user to the URL with pattern domain.com/{criteria}/search/{searchWord}.

This way I had to use a single controller to search, with a single view to view search results.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜