asp.net-mvc-2

Is there a Perfect/Model ASP.Net Website for Learning Purposes?

半腔热情 提交于 2020-01-01 18:19:16
问题 I'm looking for a 'model' website/application written in ASP.Net that illustrates current best-practices of architecture, design, code etc. that could be used as a blueprint for development? I'm working in ASP.Net webforms, but would like to get into MVC so examples from both would be very welcome. Thanks. 回答1: Nerd Dinner might be worth a look for MVC, it comes with a 185 page pdf walkthough of the code with screenshots. I think it was built as an example for the book ASP.NET MVC 1.0. There

Formatting nullable DateTime fields in strong typed View

不问归期 提交于 2020-01-01 18:17:18
问题 I have a Person class with a BornDate property in my model defined as [DisplayName("Born Date")] public DateTime? BornDate { get; set; } I use this field in my view as <td style="white-space:nowrap"> <%= Html.LabelFor(model => model.BornDate)%> <br /> <%= Html.TextBoxFor(model => model.BornDate, new { id = "bornDate" })%> <%= Html.ValidationMessageFor(model => model.BornDate, "*")%> </td> The problem is that when I am editing a Person instance with the BornDate text box is formatted as dd/MM

Passing parameters to MVC Ajax.ActionLink

岁酱吖の 提交于 2020-01-01 05:39:22
问题 How can I send the value of the TextBox as a parameter of the ActionLink? I need to use the Html.TextBoxFor <%= Html.TextBoxFor(m => m.SomeField)%> <%= Ajax.ActionLink("Link Text", "MyAction", "MyController", new { foo = "I need here the content of the textBox, I mean the 'SomeField' value"}, new AjaxOptions{ UpdateTargetId = "updateTargetId"} )%> The Contoller/Actions looks like this: public class MyController{ public ActionResult MyAction(string foo) { /* return your content */ } } Using

Display datetime model property as Short date time string

点点圈 提交于 2020-01-01 05:07:13
问题 I'm new with MVC2, and am having a formatting problem. I have a DateTime property in my Employee model that I would like displayed with the Short Date Time. This however, does not appear to be the correct method. 1 <div class="editor-field"> 2 <%: Html.TextBoxFor(model => model.DateRequested.ToShortDateString()) %> 3 <%: Html.ValidationMessageFor(model => model.DateRequested) %> 4 </div> Line 2 throws this exception: Templates can be used only with field access, property access, single

ASP.NET MVC 2 - ViewModel Prefix

走远了吗. 提交于 2020-01-01 04:37:32
问题 I want to use RenderPartial twice in my view with different models associated. The problem is that some properties are present in both models (nickname, password). They have no prefix, so even the id's or names are equal in the output. Now, if I have model errors for nickname or password, both fields get highlighted. Main View: <div> <% Html.RenderPartial("Register", Model.RegisterModel); %> </div> <div> <% Html.RenderPartial("Login", Model.LoginModel); %> </div> Login PartialView: <% using

ASP.NET MVC 2 - ViewModel Prefix

萝らか妹 提交于 2020-01-01 04:37:28
问题 I want to use RenderPartial twice in my view with different models associated. The problem is that some properties are present in both models (nickname, password). They have no prefix, so even the id's or names are equal in the output. Now, if I have model errors for nickname or password, both fields get highlighted. Main View: <div> <% Html.RenderPartial("Register", Model.RegisterModel); %> </div> <div> <% Html.RenderPartial("Login", Model.LoginModel); %> </div> Login PartialView: <% using

ASP.NET MVC - Use Reflection to find if a Controller Exists

霸气de小男生 提交于 2020-01-01 03:21:33
问题 I'm having a heck of a time figuring out how to properly implement my 404 redirecting. If I use the following <HandleError()> _ Public Class BaseController : Inherits System.Web.Mvc.Controller ''# do stuff End Class Then any unhandled error on the page will load up the "Error" view which works great. http://example.com/user/999 (where 999 is an invalid User ID) will throw an error while maintaining the original URL (this is what I want) However. If someone enters http://example.com/asdfjkl

MVC ValidateAntiForgeryToken multi-tabs problem

☆樱花仙子☆ 提交于 2020-01-01 03:21:10
问题 We'd been getting "A required anti-forgery token was not supplied or was invalid." errors, and on some further investigation, I've managed to recreate the problem in its simplest form - i'm either doing something completely wrong, or this is a limitation of the anti-forgery token system. Either way, I'd appreciate some advice! Empty MVC 2 project: one view page, one controller view: <%--Sign in form:--%> <% using(Html.BeginForm("SignIn", "Home", FormMethod.Post)) {%> <%= Html.AntiForgeryToken

Strange behaviour in ASP.NET MVC: removing item from a list in a nested structure always removes the last item

青春壹個敷衍的年華 提交于 2020-01-01 00:45:16
问题 Scenario I have a parent/child model (to be exact a small questionnaire form and a one or more number of contacts). For historic reasons, all of this would have been done on the same form so user would have a form for the parent and one child and they would hit a button to add more children. Child has a few standard fields and the same with the parent, nothing fancy. Main requirement is that the data must not touch the database until all is valid and setup while I would have to go back to

Using ValueInjecter to map between objects with different property names

风格不统一 提交于 2019-12-31 22:32:24
问题 How do I map a property from an object to another object with a different property name? I have a Product class that looks like this: public class Product : IEntity { public int Id { get; set; } public string Name { get; set; } } And the view model looks like: public class ProductSpecificationAddViewModel { public int ProductId { get; set; } public string ProductName { get; set; } } I need to do the following mapping: Product.Id => ProductSpecificationAddViewModel.ProductId Product.Name =