Ticket (Solved)

Posting back to orchard using ng-submit

I would like to end up with a form that looks something like this .....

  <form ng-submit="addName()">

   <input ng-model="producer.Name" type="text">
            <input type="submit" value="add">
        </form>`

but I am trying to do it this way which doesn't work

    @using (Html.BeginFormAntiForgeryPost(Url.Action("Index", "Registration", new { area = "Producer" }), FormMethod.Post, new { ng-submit = "addName()" }))
        {
            <input ng-model="producer.Name" type="text">
            <input type="submit" value="add">

        }

The compiler doesn't like my htmlAttributes, so how would one go about doing something like this? I would like to be able to use angulars form validation on the client, so I need to find a the way to use the antiforgery functions correctly.

Re: Posting back to orchard using ng-submit

I'm not sure if it still works, but I think you used to be able to use underscores instead of hyphens in anonymous objects, which would be replaced with hyphens (e.g. { ng_submit = "addName()" } would result in ng-submit="addName()").

If that doesn't work, simply provide a dictionary instead of an anonymous object:

new Dictionary<string, object>{ {"ng-submit", "addName()"}}

@using (Html.BeginFormAntiForgeryPost(Url.Action("Index", "Registration", new { area = "Producer" }), FormMethod.Post, new Dictionary<string, object>{ {"ng-submit", "addName()"}}))
        {
            <input ng-model="producer.Name" type="text">
            <input type="submit" value="add">

        }
Thursday, July 3, 2014 8:27:42 PM bysfmskywalker

Post a reply

You need to be signed in to post a reply.

Sign In