Click here to Skip to main content
14,734,748 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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>
}	

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 ?
Posted
Updated 25-Nov-20 15:48pm

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.
   
Comments
Heba Kamel 6-Dec-15 4:05am
   
ok, what's the solution to clear?
F-ES Sitecore 7-Dec-15 4:21am
   
In your HttpPost action for your Upload action you probably end it with something like

return View(model);

instead end it with

return RedirectToAction("Upload", "Upload")

That will re-issue another HttpGet for your page, thus resetting the form and meaning when someone presses F5 they simply re-request the blank form rather than re-submitting the last values.
redirect it to the same view from action method instead of simply rendering a view via javascript or with MVC.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900