动作链接到绝对URL(删除?)并保留参数

时间:2016-11-15 13:35:05

标签: asp.net-mvc routes asp.net-mvc-routing

我试图从动作链接发送参数后得到一个绝对网址,我需要它像

http://MySite/Controller/View/CityName

所以我将能够在结果页面上进行搜索并且不会丢失第一个参数(例如)

http://MySite/Controller/View/NewYork?Lecture=bobdillen

代码:

@foreach (var city in @ViewBag.City)
{
    @Html.ActionLink((string)@city, "LectureIn", new { @city }, null)
}

动作(LectureIn)代码:

@using (Html.BeginForm("Search", "Lecture"))
{
    <div class="form-group">
        <div id="searchLecture" class="input-group">
            @Html.TextBoxFor(m => m.SearchTerm, new { @class = "form-control", placeholder = "" })
            <span class="input-group-addon">
                <button type="submit">  <i class="glyphicon glyphicon-search"></i></button>
            </span>
        </div>
    </div>
}

并在控制器中:

public ActionResult LectureIn(string search = null)
{
    // Do Staf
    return View();
}

我试图更改路线,但没有改变

routes.MapRoute(
    "lectureIn",
    "{controller}/{action}/{id}",
    new { controller = "TMaps", action = "lectureIn", City = UrlParameter.Optional }
);
routes.MapRoute(
   name: "Default",
   url: "{controller}/{action}/{id}",
   defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

0 个答案:

没有答案