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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:40:22+00:00 2026-06-02T15:40:22+00:00

I have a problem with viewmodel, when I try to add new enregistrement to

  • 0

I have a problem with viewmodel, when I try to add new enregistrement to my database when I have view titly typed with my viewmodel I get DbEntityValidationErrors.

This is code using viewmodel :

    [HttpPost]
    public ActionResult Create(Annonce annonce)
    {
        /*
        if (ModelState.IsValid)
        {
          */  

            _userservice.addannonce(annonce);

            return RedirectToAction("Index");
        /*
        }

       return View(new AnnonceView(annonce));
         * */
    } 

But when I use my entity domain Annonce directly on view, there is any problem. Help me please and sorry for my bad english

  • 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-02T15:40:27+00:00Added an answer on June 2, 2026 at 3:40 pm

    I am assuimng your addannounce method is expecting an object of your EntityModel type. Not Viewmodel. ViewModel is specific to handle the View. It is not same as your Entity Model. You can not send a View Model which you created as it is to the entity framework to save it. You need to send an Entity Model. So probably you can read the values of ViewModel and set as the relevant property values of Entity Model and send that to be saved. Something like this

    YoueEntity.Announce objEntityAnnounce=new YoueEntity.Announce();
    //Read from the posted viewmodel and set the values to entity model.
    objEntityAnnounce.ID=annonce.ID;
    objEntityAnnounce.Title=annonce.Title;
    //Other relevant Properties as well
    
    _userservice.addannonce(objEntityAnnounce);
    

    There are libraries like AutoMapper which does this mapping, You may take a look at them,

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

Sidebar

Related Questions

I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem with base classes in WPF. I try to make a base
I have a problem with Automapper when I try use custom resolver which uses
I have a model like so: return new MyViewModel() { Name = My View
Hi I try solve this situation. I have WPF app with MVVM design. I
I've one more question. I have a view which is containing an add link.
This seems to be a pretty trivial problem that I have been stuck on
This is my first try into iPhone development and I have some UITableViewController s
This problem is very strange, maybe I have missed some small detail, since I'm
I have problem with fancybox. I want to write a function that will run

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.