🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.pl.comp.lang.csharp
Article #22123

MVC

#22123
From: 3P
Date: Wed, 23 Mar 2011 19:19
57 lines
2555 bytes
Hej.

Jestem zupełnie początkujący w MVC. Powiedzcie mi, czy mogę coś takiego  
osiągnąć.

Na stronie zwracanej z HomeController.Index mam inputa i przycisk submit.

Po wciśnięciu submita chcę wywołać metodę SearchController.Find(string  
searchCriteria) i żeby w pasku adresu pokazało się
Find/tutajToPoCzymSzukamZawartoscInputa

Mam takie routingi.

  routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

             routes.MapRoute(
                 "",
                 "",
                 new { controller = "Home", action = "Index" }
             );

             routes.MapRoute(
                "",
                "Find/{searchCriteria}",
                new { controller = "Search", action = "Find",  
searchCriteria = "" }
             );

Index.cshtml:

@using (Html.BeginForm("Find", "Search"))
{
     <label for="searchCriteria">Find playlist</label>
     <input type="text" id="searchCriteria" />
     <input id="find" type="submit" value="Find" />
}

Automatyczne testy routingu przechodzą.

	[Test]
         public void Slash_Goesh_To_HomeControllers_Index_Action()
         {
             "~/".ShouldMapTo<HomeController>(c => c.Index());
         }

         [Test]
         public void Find_Routes_To_SearchControllers_Find_Action()
         {
             "~/Find/searchCriteria".ShouldMapTo<SearchController>(c =>  
c.Find("searchCriteria"));
         }

Dlaczego po kliknięciu submita dostaję adres host/Find bez searchCriteria?  
SearchController dostaje pusty parametr.

-- 
3P
Technical Details
Message-ID: <op.vss9a6nmqh41p4@mcs>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.glorb.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!news.onet.pl!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.glorb.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!news.onet.pl!.POSTED!not-for-mail
From: 3P <3p@noserver.com>
Newsgroups: alt.pl.comp.lang.csharp
Subject: MVC
Date: Wed, 23 Mar 2011 20:19:44 +0100
Organization: http://onet.pl
Lines: 68
Message-ID: <op.vss9a6nmqh41p4@mcs>
NNTP-Posting-Host: 46.151.136.5
Mime-Version: 1.0
X-Trace: news.onet.pl 1300907995 4560 46.151.136.5 (23 Mar 2011 19:19:55 GMT)
X-Complaints-To: niusy@onet.pl
NNTP-Posting-Date: Wed, 23 Mar 2011 19:19:55 +0000 (UTC)
User-Agent: Opera Mail/11.01 (Win32)
X-Antivirus: avast! (VPS 110323-1, 2011-03-23), Outbound message
X-Antivirus-Status: Clean
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit