所有,
我正在尝试使用@using语句实现三进制,以便在某些情况下切换出@enctype
,该情况在我的三进制中定义。我收到Razor解析错误,指出我在@using
语句中缺少结尾的“}”。该错误具有误导性,因为我所有的花括号都很好。我将整个表格包括在内,因为在三进制部分中看不到任何明显的语法问题。
看起来问题是if / else块,但不确定为什么……
有什么想法为什么会有问题吗?有更好的方法吗?
@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> <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) <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) <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>
}
最佳答案
不知道为什么这不起作用,也许发布整个视图?话虽如此,如果是我,我会尝试这个...
@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" }))
{ ... }