I have two Actions in my controller with different names but when I try to send data to the second, I get an error saying:
The current request for action 'Index' on controller type 'HouseholdController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult Find(Int32) on type WhatWorks.Controllers.HouseholdController System.Web.Mvc.ActionResult Index(Int32) on type WhatWorks.Controllers.HouseholdController
Every other question on this that I've found has been to do with the Actions having the same name. I can't work out where I'm going wrong although there may be a better way to accomplish what I'm trying...
Controller Code
public ActionResult Index(int page = 1)
{
int pagesize = 10;
var model = GetDisplay().OrderBy(i => i.familyId);
return View(model.ToPagedList(page, pagesize));
}
//
// GET: /HouseholdSearch/
public ActionResult Search()
{
return PartialView("Find");
}
[HttpParamAction]
public ActionResult Find(int Id)
{
var model = GetDisplay().TakeWhile(m => m.familyId == Id);
return View("Index", model);
}
Partial View "Find"
@using BootstrapSupport
@model WhatWorks.ViewModels.HouseholdListViewModel
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset class="form-horizontal">
@Html.LabelFor(model => model.familyId, new { @class = "control-label" })
<div class="controls">
@Html.TextBoxFor(model => model.familyId, new { @class = "input-mini" })
@Html.ValidationMessageFor(model => model.familyId, null, new { @class = "help-inline" })
</div>
<div>
<button type="submit" name="Find" class="btn ">Search</button>
</div>
</fieldset>
}
HTTPParamAction Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Reflection;
public class HttpParamActionAttribute : ActionNameSelectorAttribute
{
public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)
{
if (actionName.Equals(methodInfo.Name, StringComparison.InvariantCultureIgnoreCase))
return true;
var request = controllerContext.RequestContext.HttpContext.Request;
return request[methodInfo.Name] != null;
}
}