Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello All,
I need your help here. I am developing an MVC4 application using unobtrusive.min.js and validate.min.js, but this is not working at all.
I have already tried all options
1. <add key="ClientValidationEnabled" value="true">
<add key="UnobtrusiveJavaScriptEnabled" value="true">


2. Here is my .cshtml page

@model CodeSutra.HireMe.Web.ViewModel.UserProfileVM

<link href="~/Content/Site.css" type="text/css" rel="stylesheet" />
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@{ Html.EnableClientValidation(true); }
@*@Html.ValidationSummary(true)*@
@using (Html.BeginForm("UpdateProfile", "UserProfile", FormMethod.Post, new { @id = "formUpdateProfile" }))
{
@Html.AntiForgeryToken()
@*<header id="header">


My Account | My Projects | Finance |


</header>*@






Edit Profile





<!-- /title -->



@Html.ActionLink("UpdateProfile", "UpdateProfile", "UserProfile");
<input type="submit" value="UpdateProfile" id="btnSubmit" />

}


3. Here is My controller
[AllowAnonymous]
public ActionResult UpdateProfile()
{
return View();
}



[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult UpdateProfile(UserProfileVM VM)
{
try
{
if (ModelState.IsValid)
{
var updateProfile = new UserProfile();
var userAccount = new UserAccount();
Mapper.CreateMap<userprofilevm,>();
updateProfile = Mapper.Map<userprofilevm,>(VM);
//int result = userAccount.ResgiterUser(updateProfile);
}
}
catch (Exception ex)
{
ViewBag.Message = string.Format("{0}{1}", "Error occured while registering user. Please contact site admin", ex.Message.ToString());
}
return View("Error");
}

4. My ViewModel:
using System.ComponentModel.DataAnnotations;

namespace CodeSutra.HireMe.Web.ViewModel
{
public class UserProfileVM
{
public System.Guid Id { get; set; }
public System.Guid RegistrationId { get; set; }
public System.Guid SkillId { get; set; }
public System.Guid ProjectId { get; set; }

[Required(ErrorMessage ="Required")]
public string FirstName { get; set; }

[Required]
public string LastName { get; set; }

[Required]
[DataType(DataType.EmailAddress, ErrorMessage = "Email address is not valid")]
public string Email { get; set; }

[Required]
[Display(Name = "Address1")]
public string PrimaryAddress { get; set; }

[Display(Name = "Address2")]
public string SecondarAddress { get; set; }

[Required]
public string City { get; set; }

[Required]
[StringLength(5, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 5)]
[RegularExpression("^[0-9]{5}", ErrorMessage ="Zip Code must be 5 digits long and contain only numbers.")]
public decimal Zip { get; set; }

[Required]
[StringLength(10, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 10)]
[DataType(DataType.PhoneNumber, ErrorMessage = "Telephone number is not valid")]
public decimal Telephone { get; set; }

[Required]
public System.Guid Country { get; set; }

[Required]
public string AboutMe { get; set; }

[Required]
[DataType(DataType.Url, ErrorMessage = "Website Url is not valid")]
public string WebsiteUrl { get; set; }

[DataType(DataType.ImageUrl, ErrorMessage = "Image Url is not valid")]
[Display(Name = "Upload Image")]
public string ImageUrl { get; set; }

//[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
//[DataType(DataType.Password)]
//[Display(Name = "Password")]
public string Password { get; set; }

public string ConfirmPassword { get; set; }

}
}
I would be very thankful to you all if you can help me in this.
very strange behaviour is , other forms inside the Home view are working, but for this I have added a new View folder "UserProfile", it's new Controller folder "UserProfile" and added the .cshtml and controller there. I have tried this .cshtml file in HomeController, but no luck.
Posted
Comments
thatraja 21-Apr-14 8:10am    
Do you have those js files in your project?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900