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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:10:59+00:00 2026-05-14T23:10:59+00:00

I have a partial view that inherits from ViewUserControl<Guid?> – i.e. it’s model is

  • 0

I have a partial view that inherits from ViewUserControl<Guid?> – i.e. it’s model is of type Nullable<Guid>. Very simple view, nothing special, but that’s not the point.

Somewhere else, I do Html.RenderPartial( "MyView", someGuid ), where someGuid is of type Nullable<Guid>. Everything’s perfectly legal, should work OK, right?

But here’s the gotcha: the second argument of Html.RenderPartial is of type object, and therefore, Nullable<Guid> being a value type, it must be boxed. But nullable types are somehow special in the CLR, so that when you box one of those, you actually get either a boxed value of type T (Nullable’s argument), or a null if the nullable didn’t have a value to begin with. And that last case is actually interesting.

Turns out, sometimes, I do have a situation when someGuid.HasValue == false. And in those cases, I effectively get a call Html.RenderPartial( "MyView", null ). And what does the HtmlHelper do when the model is null? Believe it or not, it just goes ahead and takes the parent view’s model. Regardless of it’s type.

So, naturally, in those cases, I get an exception saying: “The model item passed into the dictionary is of type ‘Parent.View.Model.Type’, but this dictionary requires a model item of type ‘System.Guid?'”

So the question is: how do I make MVC correctly pass new Nullable<Guid> { HasValue = false } instead of trying to grab the parent’s model?

Note: I did consider wrapping my Guid? in an object of another type, specifically created for this occasion, but this seems completely ridiculous. Don’t want to do that as long as there’s another way.

Note 2: now that I’ve wrote all this, I’ve realized that the question may be reduced to how to pass a null for model without ending up with parent’s model?

  • 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-05-14T23:11:00+00:00Added an answer on May 14, 2026 at 11:11 pm
    <% Html.RenderPartial("MyView", someGuid ?? new Guid()); %>
    

    UPDATE:

    Using editor and/or display templates in ASP.NET MVC 2.0 you can achieve the desired result. Place a Guid.ascx file in the Shared/EditorTemplates folder and include it like this:

    <%= Html.EditorFor(x => someGuid) %>
    

    or if the guid is a property of the main model:

    <%= Html.EditorFor(x => x.SomeGuid) %>
    

    Now if you put a <%= Model.HasValue %> inside the partial you can get false but not with RenderPartial.

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

Sidebar

Related Questions

I have a partial view: <%@ Control Language=C# Inherits=System.Web.Mvc.ViewUserControl<DomainModel.Entities.Product> %> <div class=item> <h3><%= Model.Name
How can I have a view render a partial (user control) from a different
I have a partial view that is shared between two controllers and I'm trying
I have a partial that renders a select box using the following method: <%=
I have this partial code: if ($getRecords = $con->prepare(SELECT * FROM AUCTIONS WHERE ARTICLE_NO
I have a control that is created like so: public partial class MYControl :
I have a view model with a collection of other objects in it. public
Anyone knows if is possible to have partial class definition on C++ ? Something
I have read about partial methods in the latest C# language specification , so
I'm trying to make an AJAXy submission and have the resulting partial be inserted

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.