In Account controller it is supposed to validate the user credentials and determine if its a successful logon. In the debugger it marked it as true (credentials were good) retrieved the info from the database on that user, and then ran the RedirectToAction(string,
string) in order to redirect the user to the view "ViewAll.cshtml". Just shows "errorpage" in jquery mobile. No real compilation errors.
I correctly identified my actionName and my controllerName (Views_IndexController.cshtml contains the action actionName). At this point I have no idea what I am doing wrong.
I figured out the problem(s). Seemed to be an issue with a number of naming conventions that I did not know beforehand. Changed everything around, and it worked.
Marked as answer by afire007 on Jan 26, 2013 02:12 AM
afire007
Member
17 Points
74 Posts
RedirectToAction(action, controller) not working
Jan 25, 2013 09:46 PM|LINK
AccountController.cshtml - Controller
// POST: /Account/Login [AllowAnonymous] [HttpPost] public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid) { SessionContext context = SessionSettings.sessionContext; ValidationScheme getLoggedInStatus = new ValidationScheme(); context.UserName = model.UserName; context.Password = model.Password; context.Domain = model.Domain; if (getLoggedInStatus.getloginStatus()) { if (Url.IsLocalUrl(returnUrl)) { return Redirect(returnUrl); } else { //Retrieve user data information AccessSqlData dataSource = new AccessSqlData(context.connectionReporting, "SELECT [ResourceUID],[ResourceName],[ResourceEmailAddress],[ResourceInitials],[ResourceType],[ResourceCreatedDate],[ResourceModifiedDate],[Resource Departments],[Resource Skillset],[Resource Grade],[ResourceGroup],[ResourceNTAccount] FROM [MRL_TimeTracking_Reporting].[dbo].[MSP_EpmResource_UserView] WHERE [ResourceNTAccount]='" + context.Domain + "\\" + context.UserName + "'"); DataTable datatab = dataSource.retrieveDataTable(); foreach (DataRow row in datatab.Rows) { context.getResourceName = row["ResourceName"] as string; context.ResourceEmail = row["ResourceEmailAddress"] as string; context.resourceInitials = row["ResourceInitials"] as string; context.ResourceGroup = row["ResourceGroup"] + ""; if (context.ResourceGroup.Equals(null)) { context.ResourceGroup = "None"; } context.ResourceNTAccount = row["ResourceNTAccount"] as string; context.ResourceCreatedDate = row["ResourceCreatedDate"] + ""; context.ResourceModifiedDate = row["ResourceModifiedDate"] + ""; context.ResourceGUID = row["ResourceUID"] + ""; } return RedirectToAction("ViewAll", "Views_IndexController"); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed, redisplay form return View(model); }AccountModel - Model
namespace GTTRazorMVC.Models { public class LoginModel { [Required] [Display(Name = "User name")] public string UserName { get; set; } [Required] [DataType(DataType.Password)] [Display(Name = "Password")] public string Password { get; set; } [Required] [Display(Name = "Domain")] public string Domain { get; set; } } }Login.cshtml
@using (Html.BeginForm()) { @Html.ValidationSummary() <ul data-role="listview" data-inset="true"> <li data-role="list-divider">Details</li> <li> @Html.LabelFor(m => m.UserName) @Html.TextBoxFor(m => m.UserName) <br/> @Html.LabelFor(m => m.Password) @Html.PasswordFor(m => m.Password) <br/> @Html.LabelFor(m => m.Domain) <select name="Domain" data-native-menu="false"> <option value="NORTHAMERICA">North America</option> <option value="EUROPE">Europe</option> <option value="JAPAN">Japan</option> <option value="CHINA">China</option> </select> </li> <li data-role="fieldcontain"> <center><input type="submit" value="Log in" /></center> </li> </ul> } </div>In Account controller it is supposed to validate the user credentials and determine if its a successful logon. In the debugger it marked it as true (credentials were good) retrieved the info from the database on that user, and then ran the RedirectToAction(string, string) in order to redirect the user to the view "ViewAll.cshtml". Just shows "errorpage" in jquery mobile. No real compilation errors.
I correctly identified my actionName and my controllerName (Views_IndexController.cshtml contains the action actionName). At this point I have no idea what I am doing wrong.
CPrakash82
All-Star
18152 Points
2830 Posts
Re: RedirectToAction(action, controller) not working
Jan 25, 2013 10:29 PM|LINK
Are you sure this is controller name, verify again.
afire007
Member
17 Points
74 Posts
Re: RedirectToAction(action, controller) not working
Jan 25, 2013 10:38 PM|LINK
Changed all my naming conventions
now it is return RedirectToAction("ViewAll", ViewsIndexController)
the ViewsIndex controller file has a method for ViewAll which returns View();
Same problems
CPrakash82
All-Star
18152 Points
2830 Posts
Re: RedirectToAction(action, controller) not working
Jan 26, 2013 01:12 AM|LINK
Change it to
return RedirectToAction("ViewAll", "ViewIndex");
afire007
Member
17 Points
74 Posts
Re: RedirectToAction(action, controller) not working
Jan 26, 2013 01:52 AM|LINK
I figured out the problem(s). Seemed to be an issue with a number of naming conventions that I did not know beforehand. Changed everything around, and it worked.