15,917,456 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Member 11897361 (Top 5 by date)
Member 11897361
26-Dec-15 1:08am
View
here is my home controller code where you can get an idea
using MvcApplication1.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApplication1.Controllers
{
public class HomeController : Controller
{
CustomerDataEntities cd = new CustomerDataEntities();
//
// GET: /Home/
public ActionResult Index()
{
return View(cd.Customers.ToList());
}
[HttpGet]
public ActionResult AddEditRecord(int? id)
{
if (Request.IsAjaxRequest())
{
if (id != null)
{
ViewBag.IsUpdate = true;
Customer Customer = cd.Customers.Where(m => m.CustomerID == id).FirstOrDefault();
return PartialView("_CustomerData", Customer);
}
ViewBag.IsUpdate = false;
return PartialView("_CustomerData");
}
else
{
if (id != null)
{
ViewBag.IsUpdate = true;
Customer Customer = cd.Customers.Where(m => m.CustomerID == id).FirstOrDefault();
return PartialView("CustomerData", Customer);
}
ViewBag.IsUpdate = false;
return View("CustomerData");
}
}
[HttpPost]
public ActionResult AddEditRecord(Customer Customer, string cmd)
{
if (ModelState.IsValid)
{
if (cmd == "Save")
{
try
{
cd.Customers.Add(Customer);
cd.SaveChanges();
return RedirectToAction("Index");
}
catch { }
}
else
{
try
{
Customer cus = cd.Customers.Where(m => m.CustomerID == Customer.CustomerID).FirstOrDefault();
if (cus != null)
{
cus.FirstName = Customer.FirstName;
cus.LastName = Customer.LastName;
cus.Email = Customer.Email;
cus.Password = Customer.Password;
cus.ContactNo = Customer.ContactNo;
cd.SaveChanges();
}
return RedirectToAction("Index");
}
catch { }
}
}
if (Request.IsAjaxRequest())
{
return PartialView("_CustomerData", Customer);
}
else
{
return View("CustomerData", Customer);
}
}
public ActionResult Delete(int id)
{
Customer Customer = cd.Customers.Where(m => m.CustomerID == id).FirstOrDefault();
if (Customer != null)
{
try
{
cd.Customers.Remove(Customer);
cd.SaveChanges();
}
catch { }
}
return RedirectToAction("Index");
}
public ActionResult ViewEmployeeDetail(int id)
{
Customer customer = cd.Customers.Where(m => m.CustomerID == id).FirstOrDefault();
if (customer != null)
{
if (Request.IsAjaxRequest())
{
return PartialView("_CustomerDetail", customer);
}
else
{
return View("CustomerDetails", customer);
}
}
return View("Index");
}
}
}
Member 11897361
8-Dec-15 20:01pm
View
thank you so much your code is working .Thanks for your time
Member 11897361
8-Dec-15 20:00pm
View
ohhh yeyyyy its working i just used the http get and post methods,thnak you so much
Member 11897361
8-Dec-15 19:56pm
View
using MvcApplication1.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
namespace MvcApplication1.Controllers
{
public class LoginController : Controller
{
//
// GET: /Login/
public ActionResult Index()
{
return View();
}
public ActionResult Login()
{
return View();
}
public ActionResult Login(Customer d)
{
using (CustomerDataEntities oe = new CustomerDataEntities())
{
var user = oe.Customers.FirstOrDefault(a => a.UserName.Equals(d.UserName) && a.Password.Equals(d.Password));
if (user == null)
{
TempData["ErrorMessage"] = "Invalid user name or password.";
return RedirectToAction("Login", "Home");
}
else
{
return RedirectToAction("Index", "Home");
}
}
}
}
}
here is my code can you just help me. m just confused here.Sorry
Member 11897361
8-Dec-15 8:35am
View
hey m having one issue here, m getting one silly error saying that
"The current request for action 'Login' on controller type 'LoginController' is ambiguous between the following action methods:
System.Web.Mvc.ActionResult Login() on type MvcApplication1.Controllers.LoginController
System.Web.Mvc.ActionResult login(MvcApplication1.Models.Customer) on type MvcApplication1.Controllers.LoginController"
What does that mean where m making mistake