我有以下错误代码
$('#Template').click(function () {
var selectedTempleteType = $('#BulkLoadActionDropDownId option:selected').val();
var path = '@Url.Content("~/Upload/DownloadBulkLoadActionTemplate?templateType=" + selectedTempleteType)';
$(this).attr("href", path);
});
显示“ selectedTempleteType”错误。
答案 0 :(得分:0)
selectedTempleteType
是客户端JS变量,您不能在运行服务器端的@Url.Content()
内使用它(并且@Url.Content()
不能正确地映射带有查询字符串的URL路径,请使用{ {1}})。您应该对此进行更改:
@Url.Action()
对此:
var path = '@Url.Content("~/Upload/DownloadBulkLoadActionTemplate?templateType=" + selectedTempleteType)';
或在客户端的var path = '@Url.Action("DownloadBulkLoadActionTemplate", "Upload")?templateType=' + selectedTempleteType;
和@Url.Action()
内部使用占位符:
replace()