在asp.net mvc4中按F5时如何清除表单中的所有字段文本 [英] How to clear all fields text in form when press F5 in asp.net mvc4

查看:45
本文介绍了在asp.net mvc4中按F5时如何清除表单中的所有字段文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一张表格

Hi,
I have a form

@using (Html.BeginForm("Upload", "Upload", FormMethod.Post, new { enctype = "multipart/form-data" })) {
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>program</legend>

        <div class="editor-label">
            Programe Name :
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.prog_name)
            @Html.ValidationMessageFor(model => model.prog_name) <span style="color: red">*</span>
            <span style="color: red">@ViewBag.name</span>
        </div>

        <div class="editor-label">
            Version Number :
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ver_number)
            @Html.ValidationMessageFor(model => model.ver_number) <span style="color: red">*</span>
            <span style="color: red">@ViewBag.ver</span>
        </div>
<p>
            <input type="submit" value="Upload"/>
        </p>
    </fieldset>
}	



当我在任何(EditorFor)和按下提交按钮之前写一个文字

我想要按F5,清除字段中的所有文本

调试时返回[HttpGet]函数

我尝试做


when I write a text in any (EditorFor) and before press submit button
I want when press F5, clear all text in fields
when debug it returns to [HttpGet] function
I try to do

this.ModelState.Clear();



但文字不清楚

任何帮助?


but text doesn't clear
any help ?

推荐答案

当您按F5时,浏览器会重新发出最后一个请求,在这种情况下是页面的GET,它将执行页面的初始请求。这将重新初始化表单数据,而不是清除它。



清除ModelState不会影响数据,只会影响有关POSTed数据有效性的信息。
When you press F5, the browser re-issues the last request, in this case the GET for the page, which will execute the initial request for the page. This will reinitialize the form data, not clear it.

Clearing ModelState doesn't affect the data, just information about the validity of the POSTed data.


从操作方法将其重定向到同一视图,而不是简单地通过javascript或MVC渲染视图。
redirect it to the same view from action method instead of simply rendering a view via javascript or with MVC.


这篇关于在asp.net mvc4中按F5时如何清除表单中的所有字段文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆