Consider the following two Models: AModel (Class A) and BModel (Class B), and two partial views: AView (bound to AModel) and BView (bound to BModel).
I have a Controller called TestController. In TestController I have the following methods:
<HttpPost>
Function Index(model as AModel) As ActionResult
Return View(model)
End Function
<HttpPost>
Function Index(model as BModel) As ActionResult
Return View(model)
End Function
In Index I have the following code:
@Using Html.BeginForm()
@<div>
@Html.Partial("~/Views/Test/AView.vbhtml") ' this is here for test only
<div><input type="submit" name="submit" value="Submit" /></div>
</div>
End Using
My partial views look like this:
@ModelType Company.Domain.Models.ModelA '(or ModelB for the other)
<div>@Html.LabelFor(Function(m) m.Name)</div>
<div>@Html.TextBoxFor(Function(m) m.Name)</div>
... and so on, several Input fields follow ...
When I fill in and submit AView I get the following error:
The current request for action 'Index' on controller type 'TestController' is ambiguous between the following action methods:
System.Web.Mvc.ActionResult Index(Company.Domain.Models.AModel) on type Company.WebUI.Controllers.TestController
System.Web.Mvc.ActionResult Index(Company.Domain.Models.BModel) on type Company.WebUI.Controllers.TestController
After some research I tried putting <ActionName("Index")> over each Index method in TestController but generates the same error (I changed the method names to AIndex and BIndex then placed the action name attribute above them and tested.)
What I'm trying to achieve: I have two forms I need my user to fill out (one after the other). Each form has it's own set of properties and validation (naturally), hence AModel and BModel. I created two matching Partial Views (partial because I will want to use those views within other main views later on).
I'm lost as to how to achieve what I want here because ASP.NET isn't recognizing the different method signatures, nor am I sure I'm going about doing this correctly under ASP.NET MVC anyway. Under a competing platform I would simply #INCLUDE my pages as needed.
I hope my explanation is clear, appreciate any advice.