asp.net mvc 4 - TempData value not persisting if used in view -


i using

tempdata["hdn"] = "1"; 

in controller if use this

  @{         var hdn = (string)tempdata["hdn"];     } 

in view tempdata["hdn"] value in getting null in post. if skip code in view persist in post. why happening?

tempdata values cleared after read.

if want value in controller after have read in view, need include in hidden field , read out form values.

something like:

<input type="hidden" name="hdn" value="@hdn" /> 

then in controller, can do:

var hdn = request.form["hdn"] 

hth


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -