I pass a string parameter like this to a controller
public ActionResult Index(string key="")
{
ViewBag.key = key;
return View();
}
And then I try to set it to a hidden value in the view. I tried 2 ways but none work.
<input type="hidden" name="UniqueLink" id="UniqueLink" value="@ViewBag.key" />
@Html.HiddenFor(u => u.UniqueLink,
new { id = "UniqueLink", Value = @ViewBag.key })
What am I doing wrong here? The values are never set at all. And if its set I need it to be available for the model when posting the form to this...
public ActionResult Add(Core.Registration model)
{
Maybe I have the complete wrong approach here...?
in controller :
public ActionResult Index(string key = "")
{
Registration registration = new Registration
{
UniqueLink= key
};
return View(registration);
}
in view :
@model Registration
@Html.HiddenFor(model => model.UniqueLink)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.