Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • klaus 15 posts 35 karma points
    Mar 03, 2021 @ 15:51
    klaus
    0

    What Model is being passed to the Surface controller?

    I would like to get the form data from a async post request. How should the surfacecontroller looks like (with parameters)?

    @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: null, 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>
    
  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Mar 03, 2021 @ 22:15
    Alex Skrypnyk
    0

    Hi Klaus

    SurfaceController is just a controller with Umbraco-specific routing.

    Just inherit a controller class from SurfaceController base class, and you have a surface controller.

    An example:

    public class MemberController : SurfaceController
        {            
    
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Login(LoginViewModel model)
        {
            return CurrentUmbracoPage();
        }
    }
    

    Read more here - https://our.umbraco.com/documentation/reference/routing/surface-controllers

    All surface controllers get routed to:

    /umbraco/surface/{controllername}/{action}/{id}
    

    Thanks,

    Alex Skrypnyk

  • klaus 15 posts 35 karma points
    Mar 04, 2021 @ 08:03
    klaus
    0

    Hi Alex Thanks for your response.

    As you can see in my View it is of type UmbracoViewPage < Product >. Can I pass a < Product > to the surface controller? I do seem to get a 500 internal server error when i do so. Dont know why.

    Thanks //Klaus

Please Sign in or register to post replies

Write your reply to:

Draft