Click here to Skip to main content
15,898,374 members

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