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 8029753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:31:55+00:00 2026-06-05T00:31:55+00:00

I have a PartialView on the index page as follows :- @{ Html.RenderPartial(ImageUpload); }

  • 0

I have a PartialView on the index page as follows :-

@{ Html.RenderPartial("ImageUpload"); }

and the PartialView looks like this :-

@model MvcCommons.ViewModels.ImageModel

<p>
   @Html.ActionLink("Create New", "Create")
</p>
<table>
    @foreach (var item in Model) {
      <tr>
        <td>
          @Html.DisplayFor(modelItem => item.FileName)
        </td>
        <td>
          @Html.DisplayFor(modelItem => item.Description)
        </td>
      </tr>
    }
</table>

Now according to the declaration in the top of the PartialView, its supposed to go inside the ViewModels.ImageModel, and inside that class I have a constructor :-

public ImageModel()
{
   XDocument imageMetaData = XDocument.Load(uploadsDir + @"/ImagesMetaData.xml");
   var images = from image in imageMetaData.Descendants("image")
                select new Image(image.Element("filename").Value,
                image.Element("description").Value);
   this.AddRange(images.ToList<Image>());
}

However, for some reason, in the ImageUpload partial View, when I debug, I am not being redirected to this ViewModel constructor, and as so the model inside the PartialView is null.

Am I missing something here?

How can I get it to actually pass through my constructor? Do I also need to do an @model in the main Index page (where is hosting the PartialView).

Thanks for your help and time

  • 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-05T00:31:57+00:00Added an answer on June 5, 2026 at 12:31 am

    The line @model MvcCommons.ViewModels.ImageModel is used to declare a strongly typed Model, but not instanciate it.

    You should use

    @{ Html.RenderPartial("ImageUpload", <yourmodel>); }
    

    or more simple :

    @Html.Partial("ImageUpload", <yourmodel>)
    

    By the way, in your case:

    @Html.Partial("ImageUpload", new ImageModel())
    

    But carefull: your Model should be constructor less and not loading/parsing XML. This should be done in a Controller (and set in the Caching system?).

    If you wish to keep your main view Model less, you can also create an Action with the Attribute ChildActionOnly for a partial rendering, and call it with @Html.Action(...): it creates a new ControllerContext.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an index page for listing products. From this page I would like
I have my main view like this: <%@ Page Title= Language=C# MasterPageFile=~/Views/Shared/Site.Master Inherits=System.Web.Mvc.ViewPage %>
I have two partial views on my main index page with a filter dropdown.
i have some header tabs on a basic index.aspx page that uses a masterpage.
I would like to have both these views: ~/Views/Customer/Index. aspx ~/Views/Customer/Index. ascx I would
I have mvc3 application here my problem is on same page i.e on Index.cshtml
I have a PartialView which I need to create a button on, and once
I have this in my partial view: <tr> <% for (int currentDay = 0;
In the controller: public ActionResult Index() { ViewData[page] = 0; return View(data); } public
I have a partial view for displaying a list of items, I use this

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.