5

たとえば、私はページにいますhttp://localhost:1338/category/category1?view=list&min-price=0&max-price=100

そして、私の見解では、何らかのフォームをレンダリングしたい

@using(Html.BeginForm("Action", "Controller", new RouteValueDictionary { { /*this is poblem place*/ } }, FormMethod.Get))
{
    <!--Render some controls-->
    <input type="submit" value="OK" />
}

私が望むのはview、現在のページ リンクからパラメーター値を取得して、フォームの get 要求を作成するために使用することです。試し@using(Html.BeginForm("Action", "Controller", new RouteValueDictionary { { "view", ViewContext.RouteData.Values["view"] } }, FormMethod.Get))ましたが、役に立ちません。

4

4 に答える 4

18

私はこのスレッドで解決策を見つけました

@(ViewContext.RouteData.Values["view"])
于 2014-02-20T09:22:33.263 に答える
4

ビュー内から引き続き Request オブジェクトにアクセスできるはずです。

@using(Html.BeginForm(
    "Action", 
    "Controller", 
    new RouteValueDictionary { 
        { "view", Request.QueryString["view"] } }, FormMethod.Get))
于 2012-09-04T15:24:28.087 に答える
0

MVC の観点からは、コントローラーからページに値を渡す必要があります。

public ActionResult ViewCategory(int categoryId, string view)
{
    ViewBag.ViewType = view;
    return View();
}

次に、ビューで access を使用します。ただし、デフォルトでは(は動的オブジェクトです)@ViewBag.ViewTypeであるため、文字列にキャストする必要があります。objectViewBag

于 2012-09-04T15:27:09.640 に答える