sai krishnan
asked on
"The resource cannot be found"
i am new to asp.net mvc.i have tried to give a action method for redirecting to another action method method but it throwing this error.i have attached the code below
design code
<table>
<tr>
<td>
@Html.ActionLink("Register ", "Index")
</td>
</tr>
</table>
@using (Html.BeginForm())
{
<table>
<tr>
<td>
@Html.LabelFor(m => m.username)
</td>
</tr>
<tr>
<td>
@Html.TextBoxFor(m => m.username)
@Html.ValidationMessageFor (m => m.username)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(m => m.Password)
</td>
</tr>
<tr>
<td>
@Html.TextBoxFor(m => m.Password)
@Html.ValidationMessageFor (m => m.Password)
</td>
</tr>
<tr>
<td>
<input type="submit" id="submit" value="submit" />
</td>
</tr>
</table>
}
controller code
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(Customer cus)
{
using (customerEntities1 ce = new customerEntities1())
{
try
{
if (ModelState.IsValid)
{
Customer cs = new Customer();
ce.Customers.Add(cus);
ce.SaveChanges();
ViewBag.alert = cus.username + " recoords are insered successfully";
ModelState.Clear();
}
}
catch (DbEntityValidationExcepti on dbEx)
{
foreach (var validationErrors in dbEx.EntityValidationError s)
{
foreach (var validationError in validationErrors.Validatio nErrors)
{
Trace.TraceInformation("Pr operty: {0} Error: {1}",
validationError.PropertyNa me,
validationError.ErrorMessa ge);
}
}
}
}
return View();
}
[HttpPost]
public ActionResult welcome(Customer cus1)
{
using (customerEntities1 ce = new customerEntities1())
{
var obj1 = from e in ce.Customers where e.username == cus1.username && e.Password == cus1.Password select e.username;
if (obj1 != null)
{
RedirectToAction("welcome" );
}
else
{
ViewBag.mes = "your user and password is not correct";
}
return View();
}
}
}
it is not redirecting to welcome action method.please help on this
1.jpg
design code
<table>
<tr>
<td>
@Html.ActionLink("Register
</td>
</tr>
</table>
@using (Html.BeginForm())
{
<table>
<tr>
<td>
@Html.LabelFor(m => m.username)
</td>
</tr>
<tr>
<td>
@Html.TextBoxFor(m => m.username)
@Html.ValidationMessageFor
</td>
</tr>
<tr>
<td>
@Html.LabelFor(m => m.Password)
</td>
</tr>
<tr>
<td>
@Html.TextBoxFor(m => m.Password)
@Html.ValidationMessageFor
</td>
</tr>
<tr>
<td>
<input type="submit" id="submit" value="submit" />
</td>
</tr>
</table>
}
controller code
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(Customer cus)
{
using (customerEntities1 ce = new customerEntities1())
{
try
{
if (ModelState.IsValid)
{
Customer cs = new Customer();
ce.Customers.Add(cus);
ce.SaveChanges();
ViewBag.alert = cus.username + " recoords are insered successfully";
ModelState.Clear();
}
}
catch (DbEntityValidationExcepti
{
foreach (var validationErrors in dbEx.EntityValidationError
{
foreach (var validationError in validationErrors.Validatio
{
Trace.TraceInformation("Pr
validationError.PropertyNa
validationError.ErrorMessa
}
}
}
}
return View();
}
[HttpPost]
public ActionResult welcome(Customer cus1)
{
using (customerEntities1 ce = new customerEntities1())
{
var obj1 = from e in ce.Customers where e.username == cus1.username && e.Password == cus1.Password select e.username;
if (obj1 != null)
{
RedirectToAction("welcome"
}
else
{
ViewBag.mes = "your user and password is not correct";
}
return View();
}
}
}
it is not redirecting to welcome action method.please help on this
1.jpg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.