c# - ASP.NET 在引号内使用 ViewBag

标签 c# asp.net viewbag

我正在尝试在 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/

相关文章:

c# 联合运算符

c# - 在 Azure 数据湖中解压 .gz 文件

asp.net-mvc-3 - ViewBag/ViewData 生命周期

c# - 无法对空引用执行运行时绑定(bind)。 ViewBag.Title 为空

asp.net-mvc-3 - MVC3 下拉列表显示每个项目的多个属性

c# - File.WriteAllLines 静默失败

c# - 如何在 MailKit ImapClient 处于空闲状态时使用它来读取消息?

asp.net - 在 ASP.NET 中总计 GridView

asp.net - 在 Web API 中获取匹配的路由名称

asp.net - 生成临时文件的 ASPX 解析器/预编译器