【发布时间】:2019-10-23 16:08:04
【问题描述】:
I have a dropdownlist which when selected, needs to update the url, so I could send this updated url via jquery ajax and get the updated result and post it back.我现在遇到的问题是我无法通过我的 jquery 调用更改查询字符串参数值之一。我将如何去做。请看下文。
<div class="col-sm-5">
@{
var href = Url.Action<MassUploadIndexController>(c => c.LoadTemplateProperties(Model.ClientId, Model.UploadType, @property.Name, @property.SelectedValueId));
}
@if (!property.IsEnabled)
{
@Html.UI().DropDownList($"Properties[{@property.Name}]", selectList: @property.Options.Select(o => new SelectListItem { Text = o.Text, Value = o.Value, Selected = o.Value == @property.SelectedValueId.ToString() }), htmlAttributes: new { @class = "propertySelector", @disabled = "disabled", @data_reloadUrl = href })
}
else
{
@Html.UI().DropDownList($"Properties[{@property.Name}]", selectList: @property.Options.Select(o => new SelectListItem { Text = o.Text, Value = o.Value, Selected = o.Value == @property.SelectedValueId.ToString() }), htmlAttributes: new { @class = "propertySelector", @data_reloadUrl = href })
}
</div>
还有剧本
$(document).on("change", ".propertySelector", function (e) {
var link = $(this).attr('data-reloadUrl');
link.val().replace("selectedValueId=00000000-0000-0000-0000-000000000000", $(this).val());
alert(link);
$.ajax({
url: link,
success: function (data) {
var newHtml = $(data);
$("#selectpropertycontainer").html(newHtml);
}
});
});
我在控制台上看到的网址是 /site1/client/77089cca-c09d-419e-8978-72aef1133c8e/upload/loadproperties?uploadType=metadata&name=ProgramId&selectedValueId=00000000-0000-0000-0000-000000000000
当下拉值被选中时我想要更改的值是 selectedValueId。我想从下拉列表选择的值中将值更新为正确的 guid。
如果您需要更多信息,请告诉我。 谢谢!
【问题讨论】:
标签: jquery asp.net-mvc