Copied to clipboard

Flag this post as spam?

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


  • Michael Falk 37 posts 59 karma points
    Mar 29, 2013 @ 08:22
    Michael Falk
    0

    Using Html.BeginUmbracoForm

    I am using Umbraco 6.0.3 MVC, and would like to make some forms that uses some SurfaceControllers, however i have no idea what to inherit or using.

    When using

    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext @using (Html.BeginUmbracoForm("LoginForm", "LoginSurfaceController")) { ...

    It just says:Error 1 'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'BeginUmbracoForm' and the best extension method overload Umbraco.Web.HtmlHelperRenderExtensions.BeginUmbracoForm(System.Web.Mvc.HtmlHelper, string, System.Type)' has some invalid arguments

    If i add:

    @using Umbraco.Web.Mvc it say the same error, but the VS error highligting also highlights Html

    I can as a workaround make Partial View which is then loaded by a Partial View Macro, but is that really the correct/only way?

    mvh
    Michael

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 29, 2013 @ 11:11
    Jan Skovgaard
    0

    Hi Michael

    Perhaps you can get some hints from this post http://our.umbraco.org/m?mode=topic&id=28394

    Hope this helps.

    /Jan

  • Charles Afford 1163 posts 1709 karma points
    Mar 29, 2013 @ 17:45
    Charles Afford
    0

    I would use just a normal form post or ajax post instead of using the umbracobeginform.  I have found this more flexable.  

    All you need is a controller that inherits from SurfaceController.

    so

    namespace

    {

    YourControllerNameSurface: SurfaceController

    {

    public ActionResult YourName (someparam sp)

    {

    }

    }

    so in your form:

    Action: YourName

    Controller: YourControllerNameSurface

     

    Hope this helps.

     

    You can also do hijacking where before the page is rendered you can drop into an action based on a doc type or template:

    Say i have a doc type of Html and a template of Form, you can do:

     

    public class HtmlController : RenderMvcController

        {

            public ActionResult Form(someparam sp)

            {            

                //logic goes here

            }

        } 

    Anytime a page with a doc type of html and template of form loads it will drop into that code.  Hope this helps.  Charlie :)

  • Charles Afford 1163 posts 1709 karma points
    Mar 29, 2013 @ 17:53
    Charles Afford
    0

    Micheal, the problem you are having is that you have

    @inherits umbraco.MacroEngines.DynamicNodeContext @using (Html.BeginUmbracoForm("LoginForm", "LoginSurfaceController")) { ..

    on the same line you need

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @using (Html.BeginUmbracoForm("LoginForm", "LoginSurfaceController")) { ..

  • Michael Falk 37 posts 59 karma points
    Mar 30, 2013 @ 09:36
    Michael Falk
    0

    Hi Charles

     

    Thank you for your input, In my code a have it on separate lines, this was just a copy paste error. However that doesn't help.

     

    Is it possible to call a surface controller from any page via jQuery? (Assuming this is a macro the user can add anywhere)

    mvh
    Michael

  • Charles Afford 1163 posts 1709 karma points
    Mar 30, 2013 @ 10:01
    Charles Afford
    0

    hi, yea i mean as long as you can make a post and called a controller and action then its possible, so javascript/jquery ajax would work.  But thats not really solving your problem :)

    Try removing and replacing  Umbraco.Web from your bin directory.  Also does everything else work with MVC/razor?  Is it just this?  Charlie :)

    How have you got your project setup at the moment?

  • Michael Falk 37 posts 59 karma points
    Mar 30, 2013 @ 10:06
    Michael Falk
    0

    Hi Charlie

    True, but i would like to go the jQuery way also :-). Can you give an example of this? I Haven't been able to find anything.

    Everything else is working in the project. My setup is made just like this description: http://www.ben-morris.com/using-umbraco-6-to-create-an-asp-net-mvc-4-web-applicatio

    I do not have an Umbraco.Web, only Umbraco.Web.UI

     

  • Charles Afford 1163 posts 1709 karma points
    Mar 30, 2013 @ 10:22
    Charles Afford
    1

    Sure.  ummm replace the Umbraco.dll in your bin.  That should the umbraco.web you need.  You could call an action using ajax using

    $.ajax({// edit to add steve's suggestion.//url: "/ControllerName/ActionName", url:'', success:function(data){// your data could be a View or Json or what ever you returned in your action method // parse your data here alert(data);}});
    But in razor you would just use something like
     @using (Ajax.BeginForm("action", "controller", option param, new AjaxOptions() { UpdateTargetId = "UpdateTargerAfterSuccessfullPostback" }, new { ID = "HtmlAttributeForTheForm" }))
  • Michael Falk 37 posts 59 karma points
    Mar 30, 2013 @ 10:26
    Michael Falk
    0

    Hmm not sure what you mean about the dll's. There is no umbraco.web in the 6.0.3 package

     

    thanks for the examples, i will play around with them also :-)

  • Charles Afford 1163 posts 1709 karma points
    Mar 30, 2013 @ 10:31
    Charles Afford
    0

    And there is a Umbraco.web in version 6.0.3 :)  Try relpacing the dlls.  So in your bin remove the umbraco dlls and replace them.  Charlie.

  • Michael Falk 37 posts 59 karma points
    Mar 30, 2013 @ 10:34
    Michael Falk
    0

    No change :-(

    If i use the Ajax.BeginForm i get:
    Error 19 The type or namespace name 'BeginForm' does not exist in the namespace 'System.Web.Mvc.Ajax' (are you missing an assembly reference?) 

    So this is kind of the same problem as with the Html.BeginForm

  • Charles Afford 1163 posts 1709 karma points
    Mar 30, 2013 @ 10:38
    Charles Afford
    0

    Are you in razor?  A .cshtml file?

  • Michael Falk 37 posts 59 karma points
    Mar 30, 2013 @ 10:42
    Michael Falk
    0

    Yes i have the dll in my bin. Remember this is al working in a Partial View, just not in a Macor. @Ajax is not working, but is working in the Partial View

    br
    Michael

  • Charles Afford 1163 posts 1709 karma points
    Mar 30, 2013 @ 10:43
    Charles Afford
    0

    Ahhhhhhh i seeee :)  Why are you trying to use it in a macro?

  • Michael Falk 37 posts 59 karma points
    Mar 30, 2013 @ 10:46
    Michael Falk
    0

    Well, as i started out with:

    I can as a workaround make Partial View which is then loaded by a Partial View Macro, but is that really the correct/only way?

    I am just thinking why do i have to make two files for this to work. Maybe  I am not understanding the Mvc/Umbraco concepts here? :-)

    If i put the same code in the Partial View Macro it is not working either

  • Charles Afford 1163 posts 1709 karma points
    Mar 30, 2013 @ 10:55
    Charles Afford
    0

    I would not use macros tbh,  you will find it so much easier with out them.  If you just create you views in the views folder and partials in your macropartials folder you should be fine.  If you show me sohw code i can help you out :)

    What you will do is start with a View say HTML.  This will have HTML.renderbody().

    This will be the template(view) that you have defined somewhere and is attached to a node in the umbraco tree.

    In your view say 'HomePage' you would then call 

    @Html.Partial('your partial view', 'your model')

    In the partial view 'your partial view'

    you would then do your ajax/form post to the controller and action, which is inherting the suface

    So all you need in Umbraco backend

    In the templates you will have your view and in the Developer/Macros you will have your partial views where if you click on one you will see 

    'UseMVCPartial' where its pointing to the physical file.

    This might be slighty diffrent in 6.0.3 i am looking at 4.11.1

    Does this make sense?

  • Michael Falk 37 posts 59 karma points
    Mar 30, 2013 @ 11:00
    Michael Falk
    0

    Hi Charles

    Yes i think that makes sense. Let me wrap up what i have:

    I have the standard layoutstuff that calls renderbody().

    Then i have a Macro that calls a MVC Partial View:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @Html.Partial("~/Views/Partials/ContactForm.cshtml",new Falk118.Models.ContactViewModel())
    

    And then the Partial View:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<Falk118.Models.ContactViewModel>
    @using Umbraco.Web
    @using Umbraco.Web.Macros
    @using Umbraco.Web.Mvc
    @if (TempData["CustomMessage"] == null)
    {
        
        using (Html.BeginUmbracoForm("CreateComment""ContactSurface"))
        {
    
        <div class="formRow">
            @Html.LabelFor(x => Model.Name) @Html.EditorFor(x => Model.Name) @Html.ValidationMessageFor(x => Model.Name)
        </div>
        
    
        <div class="formRow">
            @Html.LabelFor(x => Model.Email) @Html.EditorFor(x => Model.Email) @Html.ValidationMessageFor(x => Model.Email)
        </div>
        
    
        <div class="formRowText">
            @Html.LabelFor(x => Model.Comment) @Html.TextAreaFor(x => Model.Comment) @Html.ValidationMessageFor(x => Model.Comment)
        </div>
    
        <div class="formRow">
            <input type="submit" name="submit" value="Send" />
        </div>
        }
    }
    else
    {
     <p>@TempData["CustomMessage"]</p>    
    }
    <script type="text/javascript">
        $(document).ready(function () {
            $("form").validate();
        });
    </script>
    

     

    So i think this is what you are saying, isn't it?

  • Charles Afford 1163 posts 1709 karma points
    Mar 30, 2013 @ 11:08
    Charles Afford
    0

    Yes, but need a view that calls a partial, so in your template section in Umbraco

    HTML

    • VIEW
    • VIEW
    • VIEW
    • VIEW

     

    Then in the content tree

    Home node

    Template 

    VIEW

    Doctype

    DOCTYPE

     

    In VIEW call a partial, 

    Also where you are using @inheritsUmbraco.Web.Mvc.UmbracoViewPage<Falk118.Models.ContactViewModel> I personally have found no benefit in this and use @model Falk118.Models.ContactViewModel

    Make sense? :) Charlie.

     

    Also why do you have the javascript at the end? Should this not be taken care of though your controller and in a class somewhere?

  • Michael Falk 37 posts 59 karma points
    Mar 30, 2013 @ 11:10
    Michael Falk
    0

    I think so :-)

     

    thanks for all your help

  • Charles Afford 1163 posts 1709 karma points
    Mar 30, 2013 @ 11:12
    Charles Afford
    0

    No problem, let me see your code when you have got it and if it does not work.  Should be failry simple and should be able to call your controller and actions :)

Please Sign in or register to post replies

Write your reply to:

Draft