0

我使用了 HTMLEditor 代码,如下所示。

我只想通过单击清除一个 HTMLEditor。如何在 controller.cs 文件中找到特定的 HTML 编辑器控件?

@model Blog.Models.User
@{
    ViewBag.Title = "Register New User";
}
@using Microsoft.Web.Mvc;
@using MVC3MultiSubmitButtonExtension;
<h2>
    Register New User</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm("Create", "Home", FormMethod.Post))
{

    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Fill User Details</legend>
        <div class="editor-label">
            @Html.LabelFor(model => model.FirstName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.FirstName)
            @Html.ValidationMessageFor(model => model.FirstName)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.LastName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.LastName)
            @Html.ValidationMessageFor(model => model.LastName)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Username)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Username)
            @Html.ValidationMessageFor(model => model.Username)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Password)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Password)
            @Html.ValidationMessageFor(model => model.Password)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.EmailAddress)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.EmailAddress)
            @Html.ValidationMessageFor(model => model.EmailAddress)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.MobileNumber)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.MobileNumber)
            @Html.ValidationMessageFor(model => model.MobileNumber)
        </div>
        <p>
            @*  <input type="submit" value="Create" />*@ @*@Html.MultiSubmitButton(Url.Action("Create"), "btnCreate", "Create")*@
            @*  @Html.MultiSubmitButton(Url.Action("Cancel"), "btnCancel", "Cancel", new { @class = "cancel" })*@
            <input type="submit" id="btnSubmit" name="btnSubmit" value="Submit" />
            <input type="submit" id="btnReset" name="btnReset"  value="Reset"
                class="cancel" />
        </p>
    </fieldset>
}
<div>
    @Html.ActionLink("Click here to go Login Page", "Index")
</div>

我只想为 EmailAddress HTML 编辑器设置 string.empty。

4

1 回答 1

0

如果您想在单击按钮时重置完整的表单,您可以将按钮的类型设置为type="reset".

<input type="reset" id="btnReset" name="btnReset"  value="Reset" />

如果要清除特定字段,例如EmailAddress单击按钮,则必须侦听单击事件。首先,您必须为该按钮设置一个唯一的 ID。

<input id="clearEmailAddress" type="button" value="Clear Email Address" />

<script type="text/javascript>

$("#clearEmailAddress").click(function(){
     $(this).closest('form').find("input[name='EmailAddress']").val("");
});

</script>
于 2012-06-23T14:27:06.813 回答