Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8394185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:59:30+00:00 2026-06-09T19:59:30+00:00

I have an image uploader editor template, which is currently strongly typed to the

  • 0

I have an image uploader editor template, which is currently strongly typed to the MultiImageUploader view model. The problem is I have some custom data validation attributes that I’d like to use in the view model that calls the editor template directly, instead of routing through the MultiImageUploader view model.

Instead of calling the MultiImageUploader view model with preset validation attributes, I’d like to do something like this:

public class CreateBrandViewModel
{
    .....<snipped>.....

    [PermittedFileExtensions("jpg, jpeg, png, gif")]
    [MaxFileSize("2MB")]
    [UIHint("MultiImageUploader")]
    public HttpPostedFileBase Image { get; set; }

  //Currently this view model looks like this:
  //public MultiImageUploader Image { get; set; } <-- seperate view model 

}

I can’t use my preferred way currently because my editor template isn’t strongly typed against the CreateBrandViewModel. Is there a way I can pass the calling view model’s @model into the editor templates view? :

@model // Here? //
<div class="editor-field">
     @Html.TextBoxFor(x => x.Image, new { type = "file" })
     @Html.ValidationMessageFor(x => x.Image)
</div>

Edit 1

Just for clarification, the reason I want to do this is because I’d like to change from an Image uploader to a general purpose file uploader – which would require different validation attributes on different view models. To do this currently I’d need to create a different view model and editor template for each slightly different validation parameter variation.

Edit 2: Regarding @Joel Athertons answer

I’ve run into a few problems trying to implement this (or maybe I’m just not understanding correctly).

I’ve created the interface and the abstract class. My CreateBrandViewModel now inherits from FileUpload. FileUpload is currently empty with no shared properties. When I try model.GetType().Name I get an “Object reference not set to an instance of an object.” error. Code is as follows:

Controller passes a CreateBrandViewModel to the view:

    [HttpGet]
    public ActionResult Create()
    {
        var model = new CreateBrandViewModel();
        model.IsActive = true;

        return View(model);
    }

The Create view then calls the EditorTemplate:

@model CumbriaMD.Infrastructure.ViewModels.BrandViewModels.CreateBrandViewModel 

@Html.EditorFor(model => model.File, "EditorTemplates/MultiImageUploader")

The template then just (for simplicities purpose) looks like this:

@model CumbriaMD.Infrastructure.ViewModels.FileUploadViewModels.FileUpload

@{
    var partialView = Model.GetType().Name;
}

<h1>@partialView</h1>

Any ideas would be appreciated 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:59:31+00:00Added an answer on June 9, 2026 at 7:59 pm

    The way I would handle this would be to have an interface which all of your models that will allow uploads would implement. If you actually have common functionality, I would also couple this with an abstract model that has any common properties, attributes, etc. Then each of your individual models would either inherit the abstract class (or implement the interface if you didn’t use a class), and then you could use that as your @model statement. Then you could simply split off any one-off pieces into partial views that could do their own thing.

    public interface IFileUploadModel
    {
        // any common properties would go here
    }
    
    public abstract class FileUploadModel : IFileUploadModel
    {
        // implement the common stuff
    }
    
    public class CreateBrandViewModel : FileUploadModel
    {
        [PermittedFileExtensions("jpg, jpeg, png, gif")]
        [MaxFileSize("2MB")]
        [UIHint("MultiImageUploader")]
        public HttpPostedFileBase Image { get; set; }
    }
    
    public class SomeOtherUploadModel : FileUploadModel
    {
        // Other special stuff here
    }
    

    Then in your template.

    @model FileUploadModel
    
    @{
        // Common output code that they all do
    
        // Then the special stuff
        if (model.GetType().Name == "CreateBrandViewModel")
        {
            // Render the partial and pass it the model
            Html.RenderPartial("CreateBrandPartialView", Model);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an image uploader and cropper which creates thumbnails and I occasionally get
Having a reallllll mind pain. I have a php image uploader which is all
I have created a custom image uploader for my wordpress admin panel and need
I'm making a image uploader but I have come across 2 errors. Which are:
Thanks in advance. I have a php image uploader that I built, which is
Let's say i have an image uploader script, i want to prevent the upload
I have a site with an image uploader, and whenever a user tries to
I am trying to create a multiple image uploader and I have come across
I have encountered a problem with creating a thumbnail from an uploaded image file,
I have been working on some code to submit an uploaded image to PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.