所有
我正在尝试使用@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>
}
答案 0 :(得分:2)
不确定为什么这不起作用,也许发布整个视图?话虽如此,如果是我,我会试试这个......
@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" }))
{ ... }
答案 1 :(得分:1)
问题是由if / else块中未关闭的输入标记引起的。不知道为什么intellisense没有选择这个或为什么错误信息似乎与实际问题无关。谢谢大家
<强>之前强>
<input class="js-file-text" type="text" id="fileUploadFileName" name="fileUploadFileName">
<强>后强>
<input class="js-file-text" type="text" id="fileUploadFileName" name="fileUploadFileName" />