我正在尝试在 ASP.NET 中使用引号内的 ViewBag,如下所示:
@using (Html.BeginForm("Index?community=" + @ViewBag.community + "&lot=" + @ViewBag.lot + "",
"UploadFile",
FormMethod.Post,
new { enctype = "multipart/form-data" }))
{
<label for="file">Upload File:</label>
<input type="file" name="file" id="file" /><br><br>
<input type="submit" value="Upload File" />
<br><br>
@ViewBag.Message
}
我也试过以下方法:
@using (Html.BeginForm("Index?community=@ViewBag.community&lot=@ViewBag.lot",
"UploadFile",
FormMethod.Post,
new { enctype = "multipart/form-data" }))
{
<label for="file">Upload File:</label>
<input type="file" name="file" id="file" /><br><br>
<input type="submit" value="Upload File" />
<br><br>
@ViewBag.Message
}
是否可以在引号内使用@ViewBag?
最佳答案
ViewBag
没有什么特别之处,与其他属性一样,它是在页面上下文中可用的属性。就像在任何其他 C# 代码中一样,在构建字符串时只需引用它:
"Index?community=" + ViewBag.community
关于c# - ASP.NET 在引号内使用 ViewBag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33240078/