久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

mvc Html.BeginForm 不同的 URL 架構

mvc Html.BeginForm different URL schema(mvc Html.BeginForm 不同的 URL 架構)
本文介紹了mvc Html.BeginForm 不同的 URL 架構的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在為 DropDown 創建一個表單,如下所示:

I'm creating a form for a DropDown like this:

@{
    Html.BeginForm("View", "Stations", FormMethod.Get);
}
@Html.DropDownList("id", new SelectList(ViewBag.Stations, "Id", "Name"), new { onchange = "this.form.submit();" })
@{
    Html.EndForm();
}

如果我從下拉列表中選擇一個值,我會被重定向到正確的控制器,但 URL 不是我想要的:

If I choose a value from my dropdown I get redirected to the correct controller but the URL is not as I would like to have it:

/Stations/View?id=f2cecc62-7c8c-498d-b6b6-60d48a862c1c

/Stations/View?id=f2cecc62-7c8c-498d-b6b6-60d48a862c1c

我想要的是:

/Stations/View/f2cecc62-7c8c-498d-b6b6-60d48a862c1c

/Stations/View/f2cecc62-7c8c-498d-b6b6-60d48a862c1c

那么如何將 id= 查詢字符串參數替換為我想要的更簡單的 URL 方案?

So how do I get the id= querystring parameter replaced by the more simple URL Scheme I want?

推薦答案

帶有 FormMethod.Get 的表單將始終將其表單控件的值作為查詢字符串值回發.瀏覽器無法根據您的路由配置生成 url,因為它們是服務器端代碼.

A form with FormMethod.Get will always post back the values of its form controls as query string values. A browser cannot generate a url based on your route configurations because they are server side code.

如果您真的想生成 /Stations/View/f2cecc62-7c8c-498d-b6b6-60d48a862c1c,那么您可以使用 javascript/jquery 構建自己的 url 并重定向

If you really wanted to generate /Stations/View/f2cecc62-7c8c-498d-b6b6-60d48a862c1c, then you could use javascript/jquery to build your own url and redirect

@using (Html.BeginForm("View", "Stations", FormMethod.Get))
{
    @Html.DropDownList("id", new SelectList(ViewBag.Stations, "Id", "Name"))
}

var baseUrl = '@Url.Action("View", "Stations")';
$('#id').change(function() {
    location.href = baseUrl + '/' $(this).val();
});

附注:在 .change() 事件上提交不是預期的行為,并且會使用戶感到困惑.建議您添加一個按鈕讓用戶進行選擇,檢查它然后提交表單(處理按鈕的 .click() 事件而不是下拉列表的 .change() 事件)

Side note: Submitting on the .change() event is not expected behavior and is confusing to a user. Recommend you add a button to let the user make their selection, check it and then submit the form (handle the button's .click() event rather that the dropdownlist's .change() event)

這篇關于mvc Html.BeginForm 不同的 URL 架構的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進行身份驗證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權不起作用)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護進程或服務器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發技
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
Getting access token using email address and app password from oauth2/token(使用電子郵件地址和應用程序密碼從 oauth2/token 獲取訪問令牌)
New Azure AD application doesn#39;t work until updated through management portal(新的 Azure AD 應用程序在通過管理門戶更新之前無法運行)
主站蜘蛛池模板: av一二三区 | 国产成人精品一区二 | av一级毛片 | 国产视频欧美 | 国产一区二区在线播放 | 一区二区三区国产视频 | 成人亚洲精品 | 日本在线网址 | 国产a级黄色录像 | 久久久国产视频 | 精品国产一区久久 | 日韩成人精品一区二区三区 | 国产欧美精品一区二区三区 | 亚洲国产精品一区在线观看 | 亚洲成人一区 | 精品毛片 | 男人的天堂avav | 91精品国产色综合久久不卡98 | 91精品在线播放 | 1区2区3区视频 | 91久久爽久久爽爽久久片 | 91影院在线观看 | 亚洲九九 | 欧美日韩视频一区二区 | 四虎影视一区二区 | 国产美女久久 | 久久精品国产v日韩v亚洲 | 久久精品国产精品青草 | 日韩一区在线播放 | 在线一区二区三区 | 精品国产一区一区二区三亚瑟 | 久久逼逼| 色888www视频在线观看 | 最新国产视频 | 精品一区二区在线观看 | 欧美13videosex性极品 | 精品久久久一区二区 | 99久久99 | 中文字幕在线播放不卡 | 91久久久久| 久久精品99 |