MVC视图中的语法错误

时间:2015-08-28 08:43:39

标签: asp.net-mvc-3 razor

这个给我一个@question

的语法错误

这里有什么问题?

@{
    string question = "Really delete?";

<link href="~/Content/sweetalert/sweetalert.css" rel="stylesheet" />
<script src="~/Content/sweetalert/sweetalert.min.js"></script>
<script>
    $(function () {
        $(".delete").on("click", function (e) {
            swal({
                text: @question,
                title: "Delete Confirm",
                //some other stuff...

}

2 个答案:

答案 0 :(得分:0)

您必须以这种方式使用questiontitle: "@question"

代码:

@{
    string question = "Really delete?";
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <link href="~/Content/sweetalert.css" rel="stylesheet" />
    <script src="~/Content/sweetalert.min.js"></script>
    <script>
        $(function() {
            $(".delete").on("click", function(e) {
                swal({
                    title: "@question",
                    text: "You will not be able to recover this imaginary file!",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "Yes, delete it!",
                    closeOnConfirm: false
                });
            });
        });
    </script>

}

答案 1 :(得分:0)

text: @question应该包含在''中,如此

text: '@question'