1
Answer

Localization with CurrentCulture

Photo of Elie Todjom

Elie Todjom

7y
206
1
Hello Everybody,
 
I'm new in hier and I need some Help. I follow this example
 
http://www.c-sharpcorner.com/UploadFile/4d9083/globalization-and-localization-in-Asp-Net-mvc-4/
 
to create a asp.net Mvc app in English and German, but to my supprise the App is only showing German and not English.
 
I don't know what a did wrog hier is my code.
 
Home Controller:
 
  1. namespace FirstCargoApp.Controllers  
  2. {  
  3. public class HomeController : BaseController  
  4. {  
  5. public ActionResult Index()  
  6. {  
  7. return View(new LoginViewModel());  
  8. }  
  9. public ActionResult ChangeCurrentCulture(int id)  
  10. {  
  11. //  
  12. // Change the current culture for this user.  
  13. //  
  14. LocalisationHelper.CurrentCulture = id;  
  15. //  
  16. // Cache the new current culture into the user HTTP session.  
  17. //  
  18. Session["CurrentCulture"] = id;  
  19. //  
  20. // Redirect to the same page from where the request was made!  
  21. //  
  22. return Redirect(Request.UrlReferrer.ToString());  
  23. }  
  24. }  
  25. }  
LoginView:
  1. @model FirstCargoApp.Models.LoginViewModel  
  2. @{  
  3. ViewBag.Title = "Anmelden";  
  4. }  
  5. @ViewBag.Title.  
  6.   
  7. @using (Html.BeginForm("Login""Account"new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))  
  8. {  
  9. @Html.AntiForgeryToken()  
  10. Lokales Konto für die Anmeldung verwenden.  
  11.   
  12. @Html.ValidationSummary(true)  
  13. @Html.LabelFor(model => model.UserName, new { @class = "col-md-2 control-label" })  
  14. @Html.TextBoxFor(model => model.UserName, new { @class = "form-control" })  
  15. @Html.ValidationMessageFor(model => model.UserName)  
  16. @Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })  
  17. @Html.PasswordFor(m => m.Password, new { @class = "form-control" })  
  18. @Html.ValidationMessageFor(m => m.Password)  
  19. @Html.CheckBoxFor(m => m.RememberMe)  
  20. @Html.LabelFor(m => m.RememberMe)  
  21. Anmelden  
  22.   
  23. @Html.ActionLink("Registrieren""Register") wenn Sie kein lokales Konto besitzen.  
  24.   
  25. }  
  26. @*  
  27. @Html.Partial("_ExternalLoginsListPartial"new { Action = "ExternalLogin", ReturnUrl = ViewBag.ReturnUrl })  
  28. *@  
  29. @section Scripts {  
  30. @Scripts.Render("~/bundles/jqueryval")  
  31. }  
  32. using FirstCargoApp.LocalResource;  
  33. namespace FirstCargoApp.Models  
  34. {  
  35. public class ExternalLoginConfirmationViewModel  
  36. {  
  37. [Required]  
  38. [Display(Name = "UserName", ResourceType = typeof(Resource))]  
  39. public string UserName { getset; }  
  40. }  
  41. public class ManageUserViewModel  
  42. {  
  43. [Required]  
  44. [DataType(DataType.Password)]  
  45. [Display(Name = "Aktuelles Kennwort")]  
  46. public string OldPassword { getset; }  
  47. [Required]  
  48. [StringLength(100, ErrorMessage = "\"{0}\" muss mindestens {2} Zeichen lang sein.", MinimumLength = 6)]  
  49. [DataType(DataType.Password)]  
  50. [Display(Name = "Neues Kennwort")]  
  51. public string NewPassword { getset; }  
  52. [DataType(DataType.Password)]  
  53. [Display(Name = "Neues Kennwort bestätigen")]  
  54. [Compare("NewPassword", ErrorMessage = "Das neue Kennwort stimmt nicht mit dem Bestätigungskennwort überein.")]  
  55. public string ConfirmPassword { getset; }  
  56. }  
  57. public class LoginViewModel  
  58. {  
  59. [Required]  
  60. [Display(Name = "UserName", ResourceType = typeof(Resource))]  
  61. public string UserName { getset; }  
  62. [Required]  
  63. [DataType(DataType.Password)]  
  64. [Display(Name = "Password", ResourceType = typeof(Resource))]  
  65. public string Password { getset; }  
  66. [Display(Name = "Speichern?")]  
  67. public bool RememberMe { getset; }  
  68. }  
I have 3 Resource Files
 
Resource.en-GB
Resource.de-DE
Resource
 
For the rest i just copy it from the Tutorial up.
 
Please can someone help me
 
Thanks

Answers (1)

2
Photo of Manas Mohapatra
NA 29.3k 3.3m 7y
To resolve your issue:
 
1. Make method as public and static
2. Make sure param name should be same
3. Make sure that you shouldn't have any client side error like variable is undefined etc.. You can see error in console tab by pressing F12 in browser.
4. jQuery library reference should be added properly. 
  1. [System.Web.Services.WebMethod]  
  2. public static string saveTask(string date, string id)  
  3. {  
  4.     return "Hello " + name + Environment.NewLine + "The Current Time is: "  
  5.         + DateTime.Now.ToString();  
  6. }  
 
Accepted
0
Photo of Sbonga Mathobela
NA 68 2.7k 7y
Thanx guys....I found the soultion. I changed in the RouteConfug :settings.AutoRedirectMode = RedirectMode.Off; instead of settings.AutoRedirectMode = RedirectMode.Permanent
0
Photo of Pooja Dixit
NA 29 6 7y
It is May be possible in Server side Error Occured..
that time debugger is not properly working on..