asp.net-mvc-2

ASP.NET MVC UrlHelper.GenerateUrl exception: “Cannot use a leading .. to exit above the top directory”

坚强是说给别人听的谎言 提交于 2019-12-17 23:11:54
问题 I am using the IIS 7 Rewrite module to rewrite an incoming url like: http://server/year/all to http://server/application/controller/year/all Everything works fine, except when, while processing the rewritten request, I use MVC's UrlHelper.GenerateUrl() method: UrlHelper.GenerateUrl( "Assets", "Css", "Asset", new RouteValueDictionary(new { site = site.Name, assetPath = assetPath }), RouteTable.Routes, controllerContext.RequestContext, false); Calling this method results in an HttpException:

ASP.NET MVC: Is Data Annotation Validation Enough?

我的梦境 提交于 2019-12-17 21:53:56
问题 I'm using the Data Annotation validation extensively in ASP.NET MVC 2. This new feature has been a huge time saver, as I'm now able to define both client-side validation and server-side validation in one place. However, while I was doing some detailed testing, I realized that it's quite easy for someone to bypass the server-side validation if I relied on Data Annotation validation alone. For example, if I defined a required field by annotating the property with the [Required] attribute and

How to create pages with different permissions' views

大憨熊 提交于 2019-12-17 21:28:39
问题 I need to create different page views for different types of users. I already asked that here: How to create pages with different permissions' views And even though Aldeel's answer works, it does not seem the best solution for me. I'll explain why. I'll try to explain what I need very detailed and hopefuly some of you will be able to help me out :D I need to show different views but it's not only like that. Each user can have access to different parts of the page. I'll give an example:

ActionLink routeValue from a TextBox

末鹿安然 提交于 2019-12-17 19:54:31
问题 I'm working on the following: 1- The user enters a value inside a textBox. 2- then clicks edit to go to the edit view. This is my code: <%= Html.TextBox("Name") %> <%: Html.ActionLink("Edit", "Edit")%> The problem is I can't figure out how to take the value from the textBox and pass it to the ActionLink, can you help me? 回答1: You can't unless you use javascript. A better way to achieve this would be to use a form instead of an ActionLink : <% using (Html.BeginForm("Edit", "SomeController")) {

checkboxlist in asp.net MVC

别来无恙 提交于 2019-12-17 19:48:08
问题 I want to create a checkboxlist in asp.net mvc view and want to display week days (monday tuesday, ....). I want to save the value(s) selected by user in database. How can I do this in MVC2 Someone suggested me to use "Enumeration Types as Bit Flags" mentioned here: http://msdn.microsoft.com/en-us/library/cc138362.aspx how can I use it ? Please suggest solution. 回答1: Yes i would also suggest an enum in this scenario. Here is how you can do it in ASP.NET MVC: Your enum should look like this

Using a dash (-) in ASP.MVC parameters

萝らか妹 提交于 2019-12-17 18:10:59
问题 <% using (Html.BeginForm("SubmitUserName")) { %> <input type='text' name='user-name' /> <input type='submit' value='Send' /> <% } %> What should be a signature of a corresponding Action method to accept user-name parameter? public ActionResult SubmitUserName(string user-name) {...} Method signature above does not work for some reason ;-) I know there is an ActionNameAttribute to handle situation with a dash in action name. Is there something like ParameterNameAttribute ? 回答1: As everyone has

Populating Dropdownlist Using MVC2 Based On Another Dropdownlist (Cascading DropDownList)

两盒软妹~` 提交于 2019-12-17 17:54:08
问题 I am making an application that deals with vehicles. I need two DropDownLists: Makes: All Vehicle Makes Models: Models that belong to the selected value of the Make DropDownList How is this done in MVC2? My Idea: Do I use an ajax call when my first list is selected and then pull back the Models to bind to the Model DDL? How would model binding come into play that way? UPDATE I posted what I ended up doing as an answer. It is super simple and works great. You can use a get too if you feel so

How to implement badges?

孤者浪人 提交于 2019-12-17 17:19:46
问题 I've given some thought to implementing badges (just like the badges here on Stack Overflow) and think it would be difficult without Windows services, but I'd like to avoid that if possible. I came up with a plan to implement some examples: Audobiographer: Check if all fields in the profile is filled out. Commentor: When making a comment check if the number of comments equal 10, if so award the badge. Good Answer: When voting up check to see if vote score is 25 or higher. How could this be

HttpContext.Current.Server null

与世无争的帅哥 提交于 2019-12-17 16:59:21
问题 I have a windows service which is using a method from a class library with same asp.net solution. in class library, I have a method with following line: reader = XmlReader.Create(HttpContext.Current.Server .MapPath("~/TestDevice/Data.xml"), settings); When control comes to this line. I get exception. I tried to debug the code and found that when service tries to access this method then HttpContext.Current.Server is null . What is alternative syntax. I tried to access this class library method

Error “The view at '~/Views/Page/home.aspx' must derive from ViewPage, ViewPage<TViewData>, ViewUserControl, or ViewUserControl<TViewData>”

跟風遠走 提交于 2019-12-17 16:06:40
问题 I've just installed MVC2 and I've got a view that looks like this <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Home.Master" Inherits="System.Web.Mvc.ViewPage" %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> Home </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>Home</h2> </asp:Content> And the controller is just returning the view. But when I run the page I get this error: System