我需要在控制器中获取 Guid.Empty 并将其传递给查看。我尝试使用 ViewBag,我在控制器中添加了这段代码
public class QuestionnaireController : Controller
{
//....
ViewBag.EmptyGuid = Guid.Empty;
}
并在视图中添加了此代码
if (rowobject[6] == ViewBag.EmptyGuid) { //...}
但我在控制器中遇到了一些错误
Error 1 Invalid token '=' in class, struct, or interface member declaration
Error 2 Invalid token ';' in class, struct, or interface member declaration
出了什么问题以及如何使它起作用?
UPD
我更改了控制器中的代码(我添加了ViewBag.EmptyGuid
内部方法)
[HttpGet]
public ActionResult QuestionnaireIndex()
{
ViewBag.EmptyGuid = Guid.Empty.ToString();
FillViewBags();
return View();
}
这是我认为的脚本
@section scripts{
<script type="text/javascript"> function buttonize(cellvalue, options, rowobject) {
var buttons = '';
if (rowobject[5] == "False") {
buttons += '<input type="button" value="Edit" onclick="editQuestionnaire(' + options.rowId + ')">';
}
buttons += '<input type="button" value="Delete" onclick="deleteQuestionnaire(' + options.rowId + ')">';
if (rowobject[6] == ViewBag.EmptyGuid) {
buttons += '<input type="button" value="Publish" onclick="publishQuestionnaire(' + options.rowId + ')">';
}
else {
buttons += '<input type="button" value="Remove" onclick="removePublishQuestionnaire(' + options.rowId + ')">';
}
return buttons;
}
</script>
}