ASP.NET MVC Unbind Action Option

Is it possible to disconnect a specific action parameter from saving its value in requests?

[HttpPost]
public ActionResult MyAction(string value1, string value2)
{
        if(value1=="hi")
             ModelState.AddModelError("value1", "Can't have hi");
        //do stuff
        if(ModelState.IsValid)
           return RedirectToAction("Finish");
        else
           return View()
}


[HttpGet]
public ActionResult MyAction()
{
        return View()
}

The view consists of a simple form with two input fields (value1 and value2). After the submitted and completed checks are completed, the view is returned. I want the value of the text field in the view to be empty.

The value for the text field "value1" is saved if the model is invalid.

I tried to declare the text field as <% = Html.TextBox ("value1", null)%>, but the value is still persistent. I also tried to use [Bind (Exclude = "value1")], but does not work on a single variable.

Update 2:

, Captcha (custom solution). , , , .

0
2

ModelState["value1"].Value 
  = new ValueProviderResult(null, string.Empty, CultureInfo.InvariantCulture);

.

, , "value1", .

+4

, ? MVC ViewState, , , .

? GET POST? " " ?

: // . - ViewData? , . , .

2: ! ModelState.

+2

All Articles