と呼ばれるビューBrowse.chtml
があり、ユーザーは検索用語を入力するか、検索用語を空白のままにすることができます。検索語句を入力するときにページを表示しhttp://localhost:62019/Gallery/Browse/{Searchterm}
、何も入力しない場合にブラウザをに表示したいhttp://localhost:62019/Gallery/Browse/Start/Here
。
これを試すと、エラーが発生します。
コントローラータイプ 'GalleryController'に対するアクション 'Browse'の現在の要求は、次のアクションメソッド間で不明確です:タイプAutoApp_MVC.Controllers.GalleryControllerに対するSystem.Web.Mvc.ActionResult Browse(System.String)System.Web.Mvc.ActionResult Browse (Int32、System.String)タイプAutoApp_MVC.Controllers.GalleryController
私がMVCで行っていることはすべて初めてです。この時点で他に何を試すかわかりません。
public ActionResult Browse(string id)
{
var summaries = /* search using id as search term */
return View(summaries);
}
public ActionResult Browse(string name1, string name2)
{
var summaries = /* default list when nothing entered */
return View(summaries);
}
これもGlobal.asax.csにあります。
routes.MapRoute(
"StartBrowse",
"Gallery/Browse/{s1}/{s2}",
new
{
controller = "Gallery",
action = "Browse",
s1 = UrlParameter.Optional,
s2 = UrlParameter.Optional
});
routes.MapRoute(
"ActualBrowse",
"Gallery/Browse/{searchterm}",
new
{
controller = "Gallery",
action = "Browse",
searchterm=UrlParameter.Optional
});