Ich bin neu bei MVC und ich baue eine Website mit ASP.Net MVC5.Ich bin ein wenig verwirrt mit dem Routing-Konzept. Das Folgende ist meine route.config-Datei, die ich habe. Wenn ich auf meine Homepage oder Login - Seite gehe und meine Zugangsdaten eintrage und auf den Submit - Button klicke, sehe ich, dass ich über die Seite zur nächsten Seite gehen kann, auf der ich meine Informationen finde, aber der URI ändert sich in den Namen des Post-Aktion, die die Senden-Schaltfläche ausgelöst hat. wenn meine Heimat Login-Seite URI zum Beispiel ist diesesMVC Routing - URL ändert sich, wenn die Schaltfläche zum Senden geklickt wird
wenn anschließend auf die URL geklickt wird
http://localhost/home/submit aber die Ansicht, dass ich geladen wird Account nicht sicher, genannt, wie das funktioniert.
Auch ich die Benutzerinformationen in einer Sitzung speichern und es gibt eine Abmelden-Schaltfläche, wenn ich auf die Schaltfläche klicken Ich setze die Sitzung auf null und umleiten auf die Login-Aktion, aber dann ändert sich meine URL zu so etwas, obwohl ich keine URL habe, die einen Parameter als Teil der URL in meiner route.config hat.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Test",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "TESTVIEW", id =
UrlParameter.Optional }
);
routes.MapRoute(
name: "Invoice",
url: "{Home}/{Invoice}/{q}",
defaults: new { controller = "Home", action = "GetInvoice", q =
UrlParameter.Optional }
);
routes.MapRoute(
name: "Error",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Error", id =
UrlParameter.Optional }
);
routes.MapRoute(
name: "ResetPassword",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "ResetPassword", id
= UrlParameter.Optional }
);
routes.MapRoute(
name: "Accounts",
url: "{controller}/{action}",
defaults: new { controller = "Home", action = "AccountStatus" }
);
routes.MapRoute(
name: "Register",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Register", id =
UrlParameter.Optional }
);
routes.MapRoute(
name: "Home",
url: "Home",
defaults: new { controller = "Home", action = "Login"}
);
routes.MapRoute(
name: "Home1",
url: "",
defaults: new { controller = "Home", action = "Login" }
);
}
Aktion Methode
/// <summary>
/// Logoffs this instance.
/// </summary>
/// <returns></returns>
public ActionResult Logoff()
{
Session["AccountInfo"] = null;
//return View("Login");
return RedirectToAction("Login", new CustomerModel()); //
View("Login", new CustomerModel());
}
abschicken Aktion unter
[ValidateAntiForgeryToken]
public ActionResult Submit(CustomerModel customerModel)
{
homeAccountViewModel = new HomeAccountStatusViewModel();
homeAccountViewModel.Customer = customerModel;
if (ModelState.IsValidField("Username") &&
(ModelState.IsValidField("Password")))
{
logic here....
return View("AccountStatus", homeAccountViewModel);
}
else
{
return View("Login", customerModel);
}
}
Jede Hilfe wird ein großer Gefallen sein. Dank
Wie sieht Ihre "Submit" -Aktionsmethode aus? – Shyju
Wie wäre es mit: 'Session.Clear(); Session.Abandon(); '? – Hackerman
Ich habe bearbeitet, um die Submit-Aktionsmethode anzuzeigen. – Blossom