I have a view which calls a child action:
@Html.Action("RenderPostMessage", "JobSurface")
The controller is like this:
public ActionResult RenderPostMessage()
{
PostMessageViewModel postMessageViewModel = new PostMessageViewModel();
return PartialView("PostMessage", postMessageViewModel);
}
The partial this calls is like this:
@model PostMessageViewModel
@{
Html.EnableClientValidation(true);
Html.EnableUnobtrusiveJavaScript(true);
}
@using (Html.BeginUmbracoForm<JobSurfaceController>("HandlePostMessage", new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<p>
@Html.EditorFor(model => model.Message)
@Html.ValidationMessageFor(model => model.Message)
</p>
<p>
@Html.LabelFor(model => model.File)
@Html.TextBoxFor(x => x.File, new { type = "file" })
</p>
<p><button class="button">Post Message</button></p>
}
The 'handle post message' controller is like this:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult HandlePostMessage(PostMessageViewModel model)
{
// Some logic
}
I have a bunch of variables in the view that I need to somehow pass in to the form (as hidden input fields perhaps?) but although I know how to create hidden inputs on the partial, I've no idea how to populate them with the values from the view.
Could anyone suggest how to get the value passed through to the controller?
Many thanks.
@Html.Action("RenderPostMessage"...but your ActionResult signature is HandlePostMessage (is this just a typo?). Since you have a view model, why not just just addtestas a public property of the view model?