0

I've tried to add a .ascx user control to my EditorTemplates but doing so causes a hundred erros to pop up in my MVC 3 project. Every reference to "System." errors as "is not defined" and the compiler wants me to update them to "Global.System."

Can anyone tell me why adding the user control does this?

Thank you

UPDATE:

If i take out the code-behind files that are automatically created (and I don't think I need) then the problems seem to resolve. Very interesting...

1 Answer 1

1

User controls (stuff with runat="server") is not something that should be used in ASP.NET MVC application. They usually rely on Postbacks and ViewState which are notions that no longer exist in ASP.NET MVC. You could use an ascx partial/editor template and invoke it from a Razor view. So for example let's suppose that you have the following partial:

<%@ Control 
    Language="C#" 
    Inherits="System.Web.Mvc.ViewUserControl<AppName.SomeViewModel>" %>

<%= Html.LabelFor(x => x.Foo) %>
<%= Html.TextBoxFor(x => x.Foo) %>

You could include it from a Razor view like this:

@Html.Partial("NameOfThePartial")
Sign up to request clarification or add additional context in comments.

1 Comment

That sounds like the root of the problem. I wanted an ascx editor template, but was adding the incorrect thing to my project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.