Anand A
Anand A

Reputation: 23

How to debug "Unable to create a constant value of type 'System.Object'" in C#?

This is controller

public ActionResult login(login ob)
{
    bool mm = db.regs.Any(model => model.username == ob.username && model.password.Equals(ob.password));
    if (mm)
    {
        return RedirectToAction("welcome");
    }
    else
    {
        @ViewBag.err = "Invaid";
    }
    return View();
}

and the error in controller is

Unable to create a constant value of type 'System.Object'. Only primitive types or enumeration types are supported in this context.

Upvotes: 2

Views: 135

Answers (2)

Andrew
Andrew

Reputation: 1

I think you should use == instead of .Equals()

So your code will be:

bool mm = db.regs.Any(model => model.username == ob.username
    && model.password == ob.password);

Upvotes: -1

neer
neer

Reputation: 4082

Use == instead of Equals

model.password == ob.password

Upvotes: 3

Related Questions