user1475788
user1475788

Reputation: 123

MVC3 Hidden for value not persisting between form postback

I have a question, I have value as below which I set in an action method and the hidden value is available in the view. Now when I post a form to an action method, the hidden field value is gone. Any ideas on this?

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

        @Html.HiddenFor(model => Model.OutputStoredFileName)

        <button name="submit" class="art-button" type="submit" value="Populate" style="width: 100px">
                Attach</button>
    }


 [HttpPost]
public ActionResult Create(RunLogEntry runLogEntry, String ServiceRequest, string Hour, string Minute, string AMPM,string submit, IEnumerable<HttpPostedFileBase> file, String AssayPerformanceIssues1)
        {
        if(submit == "Populate")
         {
               //Runlogentry is the model
               if ((System.IO.File.Exists(runLogEntry.OutputStoredFileName)))
                            System.IO.File.Delete(runLogEntry.LoadListStoredFileName);  

Upvotes: 0

Views: 2247

Answers (1)

Jakub Konecki
Jakub Konecki

Reputation: 46008

Try replacing

@Html.HiddenFor(model => Model.OutputStoredFileName)

with

@Html.HiddenFor(model => model.OutputStoredFileName)

Confirm in FireBug or Fiddler that the value is posted to the server in the request.

Upvotes: 1

Related Questions