第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

對 asp-route-parameter 使用隱藏字段值

對 asp-route-parameter 使用隱藏字段值

C#
FFIVE 2023-07-09 15:25:46
我在 _PartialView 中有一個隱藏字段,其中包含我想要的值(jQuery 填充它)我需要在(foreach)asp-route-parameter 中使用相同的值<div class="js-products-list"> <input id="cropIdForProdBaseJQ" type="hidden" value="" />  @foreach (var product in Model.Products)  {    <a asp-controller="XXX" asp-action="YYY" asp-route-language="@Model.CurrentLanguage" asp-route-cropId="" id="productCard">  }因此,asp-route-cropId 應該從隱藏字段獲取值,并將其作為參數(shù)傳遞我嘗試使用 jQueryfunction (沒有任何運氣)像var neededValue = the value I got from another jQfunction$('#productCard').attr("asp-route-cropId", neededValue);能做到嗎?我將如何處理這個問題?謝謝!
查看完整描述

3 回答

?
BIG陽

TA貢獻1859條經(jīng)驗 獲得超6個贊

生成 html 時會消耗 razor 屬性。如果您從 javascript 引用此內(nèi)容,則需要一個在頁面編譯后保留的屬性。這對于您的情況來說很棘手,因為您試圖在請求完成后具體化路線。


相反,將輸入值傳遞給操作的良好語義方式是使用表單,而不是嘗試動態(tài)構建錨點。


<form method="get" asp-controller="XXX" asp-action="YYY" asp-route-language="@Model.CurrentLanguage">

    <input id="cropIdForProdBaseJQ" type="hidden" value="" />

    @foreach (var product in Model.Products)

    {

        @* Assuming you are doing something useful with "product" here *@

        <button name="PassThisId" value="@product.ProductId">Press me!</button>

    }

</form>


查看完整回答
反對 回復 2023-07-09
?
函數(shù)式編程

TA貢獻1807條經(jīng)驗 獲得超9個贊

通過在 a 標簽中添加 data-producttypeId 解決了這個問題;將productCard從“id”更改為“class”


@foreach (var product in Model.Products)


{

<a asp-controller="XXX" asp-action="YYY" asp-route-language="@Model.CurrentLanguage" asp-route-cropId="" class="productCard" 

data-producttypeId="@product.ProductTypeId">

}

我添加了一個 jQuery 函數(shù):


$('.productCard').click(function(e) {    

var cropId = $('#croptype-filter-From-ProductType').val();


var clickedCard = $(this);

var baseUrl = clickedCard.attr("href");


var newUrl = baseUrl.replace("crop-ID", cropId);

window.location.href = newUrl;

});

對字符串的替換會創(chuàng)建一個新字符串,而不是實際替換它。將新創(chuàng)建的字符串放入 href 后,一切都很好!感謝大家的意見,給了我一些很好的線索!


查看完整回答
反對 回復 2023-07-09
?
ITMISS

TA貢獻1871條經(jīng)驗 獲得超8個贊

razor 視圖中的標簽助手在服務器上執(zhí)行,其結果(HTML 標記)將發(fā)送到瀏覽器,瀏覽器將呈現(xiàn)它。所以此時anhcor tag helper已經(jīng)生成了鏈接的href屬性值。


您可以做的是,使用 JavaScript 覆蓋正常的鏈接單擊行為,從頁面讀取輸入元素值,并使用它構建新的 URL 并導航到該值。


您可以為您的 CropId 參數(shù)指定一個虛擬值。


<a asp-controller="invoices" asp-action="GetData" asp-route-name="@Model.supplierName" asp-route-cropId=1 id="productCard">Click me</a>

在 JavaScript 中


 $("#productCard").click(function (e) {

            // Stop the normal navigation

            e.preventDefault();


            //Build the new URL

            var url = $(this).attr("href");

            var date = $("#cropIdForProdBaseJQ").val();

            url = url.replace(1, date);


            //Navigate to the new URL

            window.location.href = url;


        });


查看完整回答
反對 回復 2023-07-09
  • 3 回答
  • 0 關注
  • 153 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號