如何将viewbag值作为变量放入javascript/jquery?
How to put viewbag value as a variable in javascript/ jquery?
我尝试将两个变量放入来自 viewbags 的 JQuery 中:
$("#btnAdd").click(function () {
var url = dev + "/Legacy/PutContentInThematic";
var GroupingId = $("#GroupingId_Dialog").val();
var Title = $("#Title_Dialog").val();
var Synopsis = $("#Description_Dialog").val();
var image = $("#Image_Dialog").val();
var ThematicId = @ViewBag.thematicid //Here i can't put ';'
var ThematicName = @ViewBag.Name
$.ajax({
url: url,
cache: false,
type: 'POST',
data: {
GroupingId: GroupingId,
ThematicId: ThematicId,
Title: Title,
Synopsis: Synopsis,
Image: image,
ThematicName: ThematicName
}
});
});
问题涉及最后两个变量"ThematicId"和"ThematicName",不可能放';'最后,所以第二个变量 ThematicName 不起作用。
我试图将这个变量从函数中移除,但我不再工作了。你有没有想过修复它或这个 Ajax 调用的其他解决方案?
你需要这样写:
var ThematicId = parseInt('@ViewBag.thematicid');
var ThematicName = '@ViewBag.Name';
var ThematicId = @(ViewBag.thematicid); //For int
var ThematicName = '@ViewBag.Name'; //For string
我尝试将两个变量放入来自 viewbags 的 JQuery 中:
$("#btnAdd").click(function () {
var url = dev + "/Legacy/PutContentInThematic";
var GroupingId = $("#GroupingId_Dialog").val();
var Title = $("#Title_Dialog").val();
var Synopsis = $("#Description_Dialog").val();
var image = $("#Image_Dialog").val();
var ThematicId = @ViewBag.thematicid //Here i can't put ';'
var ThematicName = @ViewBag.Name
$.ajax({
url: url,
cache: false,
type: 'POST',
data: {
GroupingId: GroupingId,
ThematicId: ThematicId,
Title: Title,
Synopsis: Synopsis,
Image: image,
ThematicName: ThematicName
}
});
});
问题涉及最后两个变量"ThematicId"和"ThematicName",不可能放';'最后,所以第二个变量 ThematicName 不起作用。
我试图将这个变量从函数中移除,但我不再工作了。你有没有想过修复它或这个 Ajax 调用的其他解决方案?
你需要这样写:
var ThematicId = parseInt('@ViewBag.thematicid');
var ThematicName = '@ViewBag.Name';
var ThematicId = @(ViewBag.thematicid); //For int
var ThematicName = '@ViewBag.Name'; //For string