Umbraco How to parse a form POST to surface controller?
Hi
I have an Ajax.beginform that POST a ProductName to a surface controller, or at least this is what i am looking for.
I can't seem to get hold of the Model. I can pass simple values with routeValues but how do I pass complex objects to the controller? I am getting an Internal Server Error 500 with the following controller:
public class NetShopController : RenderMvcController
{
public ActionResult AddProductForm(Product model)
{
var mod = model;// <-- Nothing in it and it returns a 500 error
return PartialView("~/Views/Partials/NetShop/result.cshtml", new HtmlString(Session["test"].ToString()));
}
}
The following is my View and as you can see I am only trying to POST one input field with Ajax.BeginForm
@inherits UmbracoViewPage<Product>
@using ContentModels = Umbraco.Web.PublishedModels;
@{ Layout = "master.cshtml"; }
<!-- for the section we want to show the shop header -->
@Html.Partial("~/Views/Partials/SectionHeader.cshtml", Model.Parent)
<section class="section">
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="product-image-container">
<img class="product-image" src="@Model.Photos.Url()" alt="@Model.ProductName image" />
</div>
</div>
<div class="col-md-6">
<h1>@Model.ProductName</h1>
<div class="product-price">@Model.Parent.GetProperty("DefaultCurrency").Value() @Model.Price.ToString("F")</div>
<div class="product-teaser">@Model.Description</div>
<div class="product-button">
@using (Ajax.BeginForm(actionName: "AddProductForm", controllerName: "NetShopBasketSurface", routeValues: new { product = Model }, ajaxOptions: new AjaxOptions()
{
UpdateTargetId = "form-result",
HttpMethod = "post",
InsertionMode = InsertionMode.Replace,
OnSuccess = "addProductForm.showResult",
OnFailure = "addProductForm.showResult"
}, htmlAttributes: new { id = "pform" }))
{
<div>
@Html.HiddenFor(m => m.ProductName)
<button class="product-submit button button--border--solid" type="submit" id="addProductButton">Tilføj til kurv</button>
</div> @*<button class="button button--border--solid">Tilføj til indkøbskurv</button>*@
}
</div>
<div class="product-advantages">
@if (Model.Features != null)
{
foreach (var feature in Model.Features)
{
<div class="product-advantage">
<h4>@feature.GetProperty("featureName").Value()</h4>
<h5>@feature.GetProperty("featureDetails").Value()</h5>
</div>}
}
</div>
</div>
</div>
</div>
</section>
<section class="section section--sand">
<div class="container">
<!-- todo: Check if grid is empty via a property value converter -->
@Html.GetGridHtml(Model, "bodyText", "bootstrap3-fluid")
</div>
</section>
<div id="form-result"></div>
Umbraco How to parse a form POST to surface controller?
Hi I have an Ajax.beginform that POST a ProductName to a surface controller, or at least this is what i am looking for. I can't seem to get hold of the Model. I can pass simple values with routeValues but how do I pass complex objects to the controller? I am getting an Internal Server Error 500 with the following controller:
The following is my View and as you can see I am only trying to POST one input field with Ajax.BeginForm
I am stuck!
Thanks
Hey Klaus
Can you pass in
ContentModel model
as a parameter to your method instead?Then could you use
Is this any help at all?
is working on a reply...