asp.net-mvc-3

ModelState.AddModelError - no error shown

流过昼夜 提交于 2020-01-24 06:11:45
问题 I'd like to set an error message for an email field after an exception has been caught in my controller: ... catch (EmailAlreadyExistsException emailAlreadyExistsException) { ModelState.AddModelError("Useraccount_Email", "This is an error message"); RegisterViewModel viewModel = new RegisterViewModel { Useraccount = useraccount, InformationMessages = InformationMessageHelper.GetInformationMessages() }; return PartialView(viewModel); } ... The error message should now be displayed in my view:

ModelState.AddModelError - no error shown

僤鯓⒐⒋嵵緔 提交于 2020-01-24 06:07:08
问题 I'd like to set an error message for an email field after an exception has been caught in my controller: ... catch (EmailAlreadyExistsException emailAlreadyExistsException) { ModelState.AddModelError("Useraccount_Email", "This is an error message"); RegisterViewModel viewModel = new RegisterViewModel { Useraccount = useraccount, InformationMessages = InformationMessageHelper.GetInformationMessages() }; return PartialView(viewModel); } ... The error message should now be displayed in my view:

Input with date format set from ViewModel and html class attribute

淺唱寂寞╮ 提交于 2020-01-24 04:52:10
问题 I am working with razor view engine in asp.net mvc3. Now, I need an input for a DateTime which should display the value in a fixed format (say dd-MMM-yyyy ). So I can do: [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd-MMM-yyyy}")] public DateTime StartDate { get; set; } And in the view: @Html.EditorFor(model => model.StartDate) But I need to add a class in the input. Which I think is not possible in EditorFor . So I could use @Html.TextBoxFor(model => model.StartDate,

Adding delay to Remote validation attribute MVC3

馋奶兔 提交于 2020-01-24 04:24:08
问题 I have a senario where i have to check for a Username existance in database while doing a registration page. for this i have implemented a Remote Attribute for remote validation in my model [Remote("CheckUserNameAvaliable", "User", Httpmethod="Post")] public string Username {get; set;} and my method looks like this [HttpPost] public JsonResult CheckUserNameAvaliable(string UserName) { SessionUser currentUser = this.sessionHelper.GetCurrentUser(); User user = this.userService.GetByUsername

how to write extension method for paging in mvc

拥有回忆 提交于 2020-01-24 04:14:05
问题 i've define static class to enable paging : public static class Pager { public static IEnumerable<T> PageData<T>(this IEnumerable<T> source, int currentPage, int pageSize) { var sourceCopy = source.ToList(); if (sourceCopy.Count() < pageSize) { return sourceCopy; } return sourceCopy.Skip((currentPage - 1) * pageSize).Take(pageSize); } } and i want in my controller to do like : var pagedDataCourses = products.OrderBy(p => p.productName).PageData(currentPage, pageSize); so where i can put that

MVC2 --> MVC3 Upgrade

蹲街弑〆低调 提交于 2020-01-24 02:53:13
问题 As today's MVC3 released, I would like to ask if anyone had experienced problems in upgrading from MVC2 to MVC3 (without changing anything in the views) . I'm currently using EF4, Telerik extensions Should I upgrade, or should I wait ? 回答1: The lead developer on the project I'm currently on installed and upgraded MVC2 to MVC3 RC, and the project and we're using EF4 and Telerik. We updated from RC to the release this morning and discussed the update from MVC2 to MVC3 RC. After installation, he

Best way to show account information in layout file in MVC3

感情迁移 提交于 2020-01-23 17:02:41
问题 I am using MVC3, and have a Layout file that is common for all of my Views. In the layout file, I would like to show some information regarding the currently logged in user. I got it working now, but the only way I found out how to is to set some ViewBag fields in the actions methods, and pick them up in the layout file. This means that I will have to the the ViewBag fields from all my action methods, or at least make a method that sets them, and call this method from all my action methods.

Best way to show account information in layout file in MVC3

江枫思渺然 提交于 2020-01-23 17:00:07
问题 I am using MVC3, and have a Layout file that is common for all of my Views. In the layout file, I would like to show some information regarding the currently logged in user. I got it working now, but the only way I found out how to is to set some ViewBag fields in the actions methods, and pick them up in the layout file. This means that I will have to the the ViewBag fields from all my action methods, or at least make a method that sets them, and call this method from all my action methods.

Difference between html rendered when client validation is true in MVC3

时间秒杀一切 提交于 2020-01-23 16:51:31
问题 I'm creating a brand new MVC3 site. Client side validation enabled on the web.config <appSettings> <add key="ClientValidationEnabled" value="true"/> <add key="UnobtrusiveJavaScriptEnabled" value="true"/> </appSettings> Scenario #1: Output HTML generated after a failed (client side) validation: <span data-valmsg-replace="true" data-valmsg-for="UserName" class="field-validation-error"> <span htmlfor="UserName" generated="true" class="">Please enter an email address</span> </span> Note the

Object template - Html.Display using ViewBag

吃可爱长大的小学妹 提交于 2020-01-23 16:27:11
问题 I've got following display template for object (source): @model object @if (Model == null) { @ViewData.ModelMetadata.NullDisplayText } else if (ViewData.TemplateInfo.TemplateDepth > 1) { @ViewData.ModelMetadata.SimpleDisplayText } else { foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForDisplay && !ViewData.TemplateInfo.Visited(pm))) { if (prop.HideSurroundingHtml) { @Html.Display(prop.PropertyName) } else { <div> <strong>@prop.GetDisplayName():</strong> @Html