0

I have an abstract class

public abstract class Member
{
   public string ID { get; set; }
   public string Username { get; set; }
   public int  MemberType { get; set; } 
   public abstract string MemberName { get; set; }
   public int Status  { get; set; }
}

public class Person : Member
{
   public string LastName { get; set; }
   public string FirstName{ get; set; }
}

public class Business : Member
{
   public string BusinessName { get; set; }
   public string TaxNo { get; set; }
}

The class was mapped using fluent API,

Now, is there a way to update the "Status" property from the view(having Member model) without using or going to a subclass (Person/Business)?

I just tried it, but it says "Cannot create an abstract class.", when submitting the page.

Or there is a correct way to do this?

Thanks

roggss
  • 93
  • 1
  • 8

3 Answers3

0

It sounds like your problem is that your action method has an abstract type as a parameter, which the default model binder can't do anything with. If you are dead set on using the same view for two different classes, you may need to implement your own model binder to inspect in the incoming request and decide which type, Person or Business, to instantiate.

Check out this link for more information on creating a custom model binder:

http://odetocode.com/blogs/scott/archive/2009/05/05/iterating-on-an-asp-net-mvc-model-binder.aspx

egoodberry
  • 2,746
  • 2
  • 26
  • 29
0

Not in EF. You have to instantiate an object to work with EF, and you can't instantiate an abstract class.

You could make the class not be abstract. Or you could use a stored proc to update the field, or some direct sql.

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
0

This seems like a similar problem to the one I've answered previously here:

ASP.NET MVC 3: DefaultModelBinder with inheritance/polymorphism

Community
  • 1
  • 1
Martin Booth
  • 8,485
  • 31
  • 31