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

  • Home
  • SEARCH
  • 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 8165655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:36:14+00:00 2026-06-06T19:36:14+00:00

I have a problem with my MVC 4 Application. I have a Model with

  • 0

I have a problem with my MVC 4 Application. I have a Model with code as follows:

public class MyModel
{
    [Required]
    [Display(Name = "Code")]
    public string Code { get; set; }

    [Display(Name = "Type")]
    [DisplayFormat(NullDisplayText = "")] 
    public string Type { get; set; }
}

The Code field in the Model represents a non-nullable type from the database while the Type field accepts null values. Now my problem comes when I try to load items from the Model and into my View using my Controller. Please see the following Controller code:

public ActionResult Display(string Code)
{
    MyManager manage= new MyManager();

    Model model= new Model();
    model = manage.GetItem(Code);

    MyModel obj = new MyModel();
    obj.Code = model.Code.Trim();
    obj.Type = model.Type.Trim();

    return View(obj);
 }

Basically the GetItems method comes from my manager which accepts the Code and returns data of type Model (which is the name of the table in my database).

The problem points at this line: obj.Type = model.Type.Trim(); whenever null values coming from the database occurs.

Can someone please point me to an effective way on how to handle this problem?

  • 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-06T19:36:15+00:00Added an answer on June 6, 2026 at 7:36 pm

    You could try to check the database return before to copy to ViewModel object.

    obj.Type = provider.Type != null ? provider.Type.Trim() : string.Empty;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic MVC view model with annotations, for example: [Required(ErrorMessage=Your Name Required)]
i have a problem with session in my webapplication (asp.net mvc rc2). the application
I have a problem with portlet. When i write in portlet.xml standart line <portlet-class>com.liferay.util.bridges.mvc.MVCPortlet</portlet-class>
I am using asp.net mvc 2.0(default binding model) and I have this problem. I
In my MVC application I have a problem with passing data from view to
In my MVC application I have a View Model that looks similar to this:
I have small problem with Spring MVC. Basically what I'm trying to do is
I seem to have a problem with getting MVC to fill in my custom
i have a problem i am developing an asp.net mvc project. Website is in
I have a problem when i using Mschart on my MVC project, when i

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.