If I have the following strongly typed view:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<XXX.DomainModel.Core.Locations.Location>" %>
Where Location is an abstract class.
And I have the following controller that accepts a strongly typed model using POST:
[HttpPost] public ActionResult Index(Location model)
I get a runtime error indicating "Unable to create abstract class
Which, of course, makes sense. However - I'm not sure what the best solution is here.
I have many specific types (about 8), and this is a view in which you can edit the properties of an abstract class.
What they tried to do to me was to create overloads for all different specific types and execute my logic in a general method.
[HttpPost] public ActionResult Index(City model) { UpdateLocationModel(model); return View(model); } [HttpPost] public ActionResult Index(State model) { UpdateLocationModel(model); return View(model); }
etc.
And then:
[NonAction] private void UpdateLocationModel (Location model) {
But this does not work either , MVC complains that the methods of action are ambiguous (also makes sense).
What should we do? Can we just not get attached to an abstract model?
RPM1984 Oct. 25 '10 at 6:19 2010-10-25 06:19
source share