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:
I have a form
@using (Html.BeginForm("Upload", "Upload", FormMethod.Post, new { enctype = "multipart/form-data" })) {


        <div class="editor-label">
            Programe Name :
        <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"></span>

        <div class="editor-label">
            Version Number :
        <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>
            <input type="submit" value="Upload"/>

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

but text doesn't clear
any help ?
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.
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.

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