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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:15:44+00:00 2026-06-03T16:15:44+00:00

This is my action view : public ActionResult promo() { var model = (from

  • 0

This is my action view :

public ActionResult promo()
{
    var model = (from p in entity.promotion
                 where p.vehicule.Idag == User.Identity.Name
                 select p).ToList();
    return View(model);
}

This is my HttpPost Action :

[HttpPost]
public ActionResult promo(string idv, string dd, string df, string remise)
{
    try
    {
        //some code
            ViewData["Resultat"] = "L'ajout de promotion à reussi";
            return View();
        }
        else
        {
            ViewData["Resultat"] = "Une promotion existe deja dans cette periode";
            return View();
        }
    }
    catch (Exception)
    {
        ViewData["Resultat"] = "L'ajout de promotion à echoué Veillez verifiez le Matricule de véhicule ou ressayer plus tard ";
        return View();
    }
} 

when i call my action i gét this error :

La référence d’objet n’est pas définie à une instance d’un objet.

at this line :

<% foreach (var item in Model) { %>

my page works fine when i navigate between page, even after getting this error when i go to the url and click on go keys it work’s.
I think something simple is missing here?

  • 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-03T16:15:45+00:00Added an answer on June 3, 2026 at 4:15 pm

    It looks like your view requires a model. In the first instance you are giving it a proper model with:

    return View(model);
    

    In the second case you are not passing a model on any branch:

    return View();
    

    Behind the scenes, when you iterate over a foreach loop, Model.GetEnumerator() is called, and if model is null, you get the null reference exception that you are seeing. You need to make sure that the model is not null, and you can easily do so using Enumerable.Empty<T>();

    return View(System.Linq.Enumerable.Empty<PromotionType>());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Action: public ActionResult AddCategory(Category newCategory) { ...//newCategory.Name is filled up return
I have this action method in C#: public ActionResult Index() { ViewBag.Message = Hello;
I have an MVC controller that has this Action Method: [HttpPost] public ActionResult SubmitAction()
I have the following action [GET(Foo)] public virtual ActionResult Foo() { return View(new FooViewModel());
I have a controller action which renders a partial view: public ActionResult Details(int id)
I am trying to test an ActionResult that returns a partial view. This action
I have called a view from another with Html.Action method. I want to call
My model is a simple parent/child representation looking like this public class Parent {
I'm trying to pass some value using TempData[SomeValue] to another action using this.RedirectToAction(Action); public
I have a controller that looks like this: public ActionResult Sold() { using (WipDBEntities

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.