Q:

MVC Razor helpers do not render proper ID and Name attributes for fields of interface derived classes

I have a class which looks like this:
public class ApplicationFormModel
    {
        protected ApplicationFormModel()
        {
            CurrentStep = ApplicationSteps.PersonalInfo;
            PersonalInfoStep = new PersonalInfo();
        }

        public PersonalInfo PersonalInfoStep { get; set; }
        public IEducationalBackground EducationalBackgroundStep { get; set; }
        public IAboutYou AboutYouStep { get; set; }
        public IOther OtherStep { get; set; }
    }

where IEducationalBackground, IAboutYou, and IOther are interfaces. I do not use this class directly, but I use derived classes of this one which upon instantiation create the proper instances of EducationalBackgroundStep, AboutYouStep, and OtherStep.
In my view, I am using Razor Helpers such as
@Html.TextBoxFor(model => (model.EducationalBackgroundStep as ApplicationFormModels.EducationalBackgroundAA).University, new {@class = "form-control", type = "text", autocomplete = "off"})

The field 'University', for example, is NOT part of the Interface and I therefore need the cast to access it. Everything is fine for properties of the interface itself, but those which I need to cast for do not end up having the correct ID and Name properties. 
For example, instead of EducationalBackgroundStep_University as ID, I only get University. This causes the form to not include this value when submitting it. 
I did not have this issue before when I used a base class instead of an interface, but then I had to include the EducationalBackgroundStep, AboutYouStep, and OtherStep in each derived class (and have it then of the correct derived type), but that is what I wanted to avoid. 
Is there any way around this? Thank you very much!

A:

The issue with the ID generation is because you are using casting (x as y) and the TextBoxFor expression handler can't determine what the original model property was (more to the point, it doesn't make sense to use the original model property as you're not using it any more, you're using the cast property)
Example fiddle: https://dotnetfiddle.net/jQOSZA
    public class c1
    {
        public c2 c2 { get; set; }
    }

    public class c2
    {
        public string Name { get; set; }
    }

    public ActionResult View(string page, bool pre = false)
    {
        var model = new c1 { c2 = new c2 { Name = "xx" } };
        return View(model);
    }

View
@model HomeController.c1
@Html.TextBoxFor(x=>Model.c2.Name)
@Html.TextBoxFor(x=>(Model.c2 as HomeController.c2).Name)

The first textboxfor has ID c2_Name while the second has just Name
You have two options: 
1) use concrete classes rather than interfaces for your viewmodel
2) don't use TextBoxFor and instead use TextBox and specify the ID manually (but then you'll lose refactoring)
@Html.TextBox("c2_Name", (Model.c2 as HomeController.c2).Name)

This will give you the ID you're expecting, but as @StephenMuecke rightly points out, this might not bind correctly when you do the POST - so you may still be stuck... but at least it answers the question.

