c# - 在@using 语句中使用三元

标签 c# asp.net-mvc-3 razor

全部,

我正在尝试使用@using 语句实现一个三元组,以便在我的三元组中定义的某些情况下切换出@enctype。我收到 Razor 解析错误,指出我在 @using 语句中缺少结束符“}”。这个错误具有误导性,因为我所有的花括号都匹配得很好。我包含了整个表格,因为我看不到三元部分的语法有任何明显的问题。

看起来问题是 if/else block ,但不确定为什么......

知道为什么这是有问题的吗?有更好的方法吗?

@using(Ajax.BeginForm("ProcessCompose", 
                      "ClubOpeningTool",
                      FormMethod.Post,
                      new AjaxOptions { UpdateTargetId = "update_panel" },
                      new { enctype = (fileAttachmentUnsupported ?  "application/x-www-form-urlencoded" : "multipart/form-data"), 
                      id = "ComposeForm" }))
{

    @Html.ValidationSummary(true)
     <fieldset style="width:90%">
         <p class="required"><strong>* Required</strong></p>
         <div id="update_panel"></div>
         <div>
             <span style="font-weight:bold; font-size:14px; color:#000000;">To:</span>
         </div>
         <div>
             <table id="compose" class="table-grid">
                 <tr>
                     <td><strong>Available @(isTeam? "Team Mambers": Model.Mode)</strong> <br />
                         @Html.ListBox("AvaliableRecipients", Model.AvailabeRecipients, new{@class="ncb-listbox"})
                     </td>
                     <td><button id="addAllRecipient" type="button">>></button><br /><button id="addRecipient" type="button">> </button><br /><button id="removeRecipient" type="button">< </button><br /><button id="removeAllRecipient" type="button"><<</button>
                         <script type="text/javascript">
                             $(function () {
                                 $('#addRecipient').click(function () {
                                     $('#AvaliableRecipients option:selected').appendTo('#Recipients');

                                 });
                                 $('#addAllRecipient').click(function () {
                                     $('#AvaliableRecipients option').appendTo('#Recipients');
                                     $("#Recipients option").attr("selected", "selected");

                                 });

                                 $('#removeRecipient').click(function () {
                                     $('#Recipients option:selected').appendTo('#AvaliableRecipients');
                                 });

                                 $('#removeAllRecipient').click(function () {
                                     $('#Recipients option').appendTo('#AvaliableRecipients');
                                 });

                             });

                             $("form").submit(function () {
                                 $('#Recipients').find("option").attr('selected', 'true');
                             });
                         </script>
                     </td>
                     <td><strong>Current Recipients</strong>&nbsp;<span class="required">*</span><br />
                         @Html.ListBox("Recipients", Model.Recipients,new{@class="ncb-listbox"})<br /><span class="messageBottom">@Html.ValidationMessageFor(model => model.Recipients)</span>
                     </td>
                 </tr>

             </table>

         </div>

         <div>
             @Html.LabelFor(model => model.Subject) &nbsp;<span class="required">*</span>
         </div>
         <div>
             @Html.EditorFor(model => model.Subject)<br />
             <span class="messageBottom">@Html.ValidationMessageFor(model => model.Subject)</span>
         </div>
        @if (!fileAttachmentUnsupported)
        {
            <div>
                <label>
                    File Attachment @Html.DisplayFor(model => model.FileName)
                </label> <i>(9MB file size limit)</i>

            </div>

            <input class="js-file-text" type="text" id="fileUploadFileName" name="fileUploadFileName">

            @Html.TextBoxFor(model => model.FileAttachment, new {type = "file", @class = "js-file-field"})
            <a class="btn blue js-file-btn">Browse</a>
        }
        else
        {
              <div>
                <label>
                    <b>Attachment feature not available for Internet Explorer 10 (IE10 or earlier)</b>
                </label> 
              </div>
        }


         @Html.HiddenFor(model => model.EmailID)
         @Html.HiddenFor(model =>model.NewClubId)
         @Html.HiddenFor(model =>model.Mode)
         @Html.HiddenFor(m => m.DraftOrSentViewMode)
         <div>
             @Html.LabelFor(model => model.Body)&nbsp;<span class="required">*</span>
         </div>
         <div>
             @Html.TextAreaFor(model => model.Body)<br />
             <span class="messageBottom">@Html.ValidationMessageFor(model => model.Body)</span>
         </div>


         <p>
             <input type="submit" id="btnComposeSend" name="Command" value="Send" class="btn blue saveSend"/>
             @if (! isTeam) {
                <input id="btnComposeSave" type="submit" name="Command" value="Save" class="btn blue saveSend"/>
             }
         </p>
     </fieldset>


}

最佳答案

不确定为什么这不起作用,也许发布整个 View ?话虽如此,如果是我,我会试试这个……

@using(Ajax.BeginForm(
        "ProcessCompose", 
        "ClubOpeningTool",
         FormMethod.Post,
         new AjaxOptions { UpdateTargetId = "update_panel" },
         new { @enctype = (fileAttachmentUnsupported ?  "application/x-www-form-urlencoded" : "multipart/form-data"), id = "ComposeForm" }))
{ ... }

关于c# - 在@using 语句中使用三元,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28963946/

相关文章:

asp.net-mvc - 带有 MVC Razor 的输入类型复选框

c# - Razor - 使用 foreach,每第 n 个项目插入 html

c# - Canvas 的 .MoveUp 使用什么值

c# - 从 HTTPClient 响应中解压 GZip 流

c# - 在 Controller 和 View 之间修改的实体

c# - WCF 服务返回 "requested service ' .. .' could not be activated"第一次从 MVC 站点访问它

c# - Html.ActionLink 不能在全局 Razor 助手中使用

c# - 使用匿名方法

c# - C# 中的“向后”公钥/私钥加密,我该怎么做?

asp.net-mvc-3 - MVC 3 Html.RenderPartial 与 Html.Partial