Ok, so I worked out how to call a certain method in the controller by name.
Unfortunately when I do that (its a partial view being shown in a Telerik
tab) it loads fine on initial load but when the submit posts back to the
controller it only returns the view (and all of the stuff in the _Layout
page is not sent back). This results in all of the JQuery scripts being
missing so the page Javascript blows up.

I think I shall revert to simpler navigation and do away with the tabs for
now. Keep it simple for now. Unless there's an alternate parameter to pass
the BeginForm to tell it its a partial page load. (or rather it needs the
_Layout of the parent page).

cheers,
Stephen


On Mon, Jul 14, 2014 at 2:44 PM, Jano Petras <jano.pet...@gmail.com> wrote:

> *Is it possible to have two HttpPost with different names, and call them
> via specifying the name in the BeginForm() ?*
>
> Yes, this will work.
>
>
> *So that actual issue with it calling the wrong method seemed to be the
> BeginForm with no parameters was using the parameters of the other form *
>
> The generated <form> element had action left as empty, which by default
> submits to the same URL that the page originated from.
>
>
> There is no way to differentiate between two action methods using the same
> name and same HTTP verb - just by parameters AFAIK. They would have to be
> called differently.
>
>
> Cheers,
> j.
>
>
> On 14 July 2014 16:35, Stephen Price <step...@perthprojects.com> wrote:
>
>> No, both are [HttpPost]
>>
>> I've also realised I had two different Html.BeginForms. one with no
>> parameters and the other with the name of the method I wanted it to use. Is
>> it possible to have two HttpPost with different names, and call them via
>> specifying the name in the BeginForm() ?
>>
>> So that actual issue with it calling the wrong method seemed to be the
>> BeginForm with no parameters was using the parameters of the other form (on
>> a different tab). Will experiment and see if I need to move it or can
>> specify by name as well as Action type.
>>
>>
>> On Mon, Jul 14, 2014 at 2:23 PM, Jano Petras <jano.pet...@gmail.com>
>> wrote:
>>
>>> With MVC controllers and two methods sharing the same name - they have
>>> to differ by HTTP verb (get / post). If the action method is not decorated
>>> by [HttpGet] or [HttpPost] it is considered both. Are these two being
>>> decorated by different verb ?
>>>
>>>
>>>
>>>
>>> On 14 July 2014 16:15, Stephen Price <step...@perthprojects.com> wrote:
>>>
>>>> Hey all,
>>>>
>>>> Just hit an error in my mvc controller after I added a new method to
>>>> it. It was complaining that I wasn't providing a value for a second
>>>> property. I was a bit confused for a second until I realised that it was
>>>> calling my newly added method when my intent was that it should still be
>>>> calling the original method.
>>>>
>>>> That probably doesn't make sense. Original method being called as
>>>> httppost was working fine. New method with different signature (two
>>>> parameters) is now being called instead. I realise now what's going on,
>>>> that methods on your controllers are called based on their signature (name
>>>> doesn't matter). It's a bit to get my head around when compared with WCF or
>>>> web services where you can call a named method in a class and you can have
>>>> as many as you like as the name is part of the signature. It would seem
>>>> that MVC controllers (and WebApi) you can only have one of each type of
>>>> call.
>>>> Or do I need to add extra routes to be able to have additional methods
>>>> on my controller? (ie a method with three parameters)
>>>>
>>>> So my question is, what to do to group like functionality together when
>>>> you have to split everything up into its own controller? I guess the
>>>> controller could be treated as a facade into a class (with each class
>>>> having whatever methods you like on it). Is that the normal way to go? With
>>>> lots of different calls I imagine you'd end up with dozens of controllers.
>>>> Also what do you do when you have more than one call from a view? It
>>>> seems a view matches up with a controller so if you have one view with say
>>>> 5 different calls on it (ajax calls for example), you'd need a different
>>>> controller for each one as you can't put them into a single controller.
>>>>
>>>> I'm sure there's a good explanation of this somewhere in an MVC book
>>>> somewhere but i'm not even sure what you call this structure.
>>>>
>>>> Sorry if my question is a bit vague. :)
>>>> cheers,
>>>> Stephen
>>>>
>>>
>>>
>>
>

Reply via email to