asp.net-mvc-2

Built in method to encode ampersands in urls returned from Url.Action?

断了今生、忘了曾经 提交于 2019-12-04 21:59:09
问题 I am using Url.Action to generate a URL with two query parameters on a site that has a doctype of XHTML strict. Url.Action("ActionName", "ControllerName", new { paramA="1" paramB="2" }) generates: /ControllerName/ActionName/?paramA=1&paramB=2 but I need it to generate the url with the ampersand escaped: /ControllerName/ActionName/?paramA=1&paramB=2 The fact that Url.Action is returning the URL with the ampersand not escaped breaks my HTML validation. My current solution is to just manually

ASP.NET MVC Render View to a string for emailing

倾然丶 夕夏残阳落幕 提交于 2019-12-04 21:54:01
问题 I want to use MVC views to create the body for an email and I have come across this (http://www.brightmix.com/blog/renderpartial-to-string-in-asp-net-mvc/) but it doesn't seem to work with strongly typed views (ViewContext is null). But I was after something the would render a full view including a masterpage. I thought that if there was a way of just invoking a view with out redirecting and just writing to a different stream and sending the email within the controller that might do it, but I

Is this bug ?…got reason behind circular reference … how to solve but?

谁说我不能喝 提交于 2019-12-04 21:09:58
i have asp.net mvc application where my model has a relation like "Question can have multiple answers". So while creating its .dbml file and classes question class would contain the EntitySet right? but each object in the EntitySet (means Answer object) will having the Property as "Question" , so framework automatically creates there circular reference and dependencies. which does comes in focus when we going to serialize the List of Question (List) to generate the json output, for particular action in controller. If we use [ScriptIgnore] attribute to property as "Answers" in "Question" class

How to make sure my created filedownload is UTF-8? (and not UTF-8 without BOM)

99封情书 提交于 2019-12-04 20:32:18
问题 i've made a download function to download messages to a CSV file (code is below). Now when i open it up in notepad or notepad++ i see this: é NY ø ╬ ║► ░ ê ö (and that is what is in the database btw) Now, when i open it up in Ms-Excel it shows this: é NY ø ╬ â•‘â–º â–‘ ê ö When i open it up in notepad++, it says it's encoded in 'UTF8 without BOM'. When i encode it (in notepad++) to UTF-8, all goes well (that is, Excel shows the right chars too) But how can i make sure that the file i

Nested areas in MVC 2 / MVC 3 / MVC 4

余生颓废 提交于 2019-12-04 20:06:22
问题 Since MVC 2 we can create areas easily. Now my question is related to nested areas (areas inside of areas). Select my " father " area folder, Right-mouse-click > Add > NO option for a new Area . Is it possible to do it in some other way ? or will this option be available in the near future? 回答1: I realise this is an old question but I'll answer it in case anyone else is trying to figure it out. A solution to this is to create areas that use a different routing value at a lower level than area

How do I get the RouteData associated with the parent action in a partial view?

我与影子孤独终老i 提交于 2019-12-04 19:51:40
问题 In the action for a PartialView, I'd like to know the RouteData associated with the Parent Action. This partial view is part of my masterpage template, and I'd like for it to know the Controller and Action that was called as part of the page rendering. In my PartialView's action, I inspect RouteData.Values["controller"] and RouteData.Values["action"] , but I only get the controller and action for my PartialView. Any suggestions? 回答1: --edit-- It looks like off of the ControllerContext (from

ASP.NET MVC 2 i18n

扶醉桌前 提交于 2019-12-04 19:33:38
I found the following page on i18n and ASP.NET: http://wiki.asp.net/page.aspx/55/internationalization/ The videos were very helpful although they apply to ASP.NET WebForms more than ASP.NET MVC, e.g., the videos show you how to internationalize controls rather than text -- which leads me to another realization: there isn't (or I couldn't find) a resources folder in my MVC applications -- just folders like AppData. Is there a simple way (like in the videos) to internationalize plain text in ASP.NET MVC? If not, do I have to use some sort of ASP control? There's a guide here: http://adamyan

Asp.Net MVC2 Clientside Validation and duplicate ID's problem

给你一囗甜甜゛ 提交于 2019-12-04 19:31:11
I'm using MVC2 with VS2010 I have a view that has two partial views in it: "Login" and "Register" both partial views contains the Email address field i use the following in both partial views: <%: Html.TextBoxFor(model => model.EmailAddress ) %><br /><%: Html.ValidationMessageFor(model => model.EmailAddress) %> if i use both partial views on one page, it ends up having duplicate id's so validation happens across both views (even thopugh they are in seperate forms) how can i go about eliminating this For some controls you can specify the HTML attributes in an overload like this: <%: Html

How do I construct an if statement within a MVC View

风流意气都作罢 提交于 2019-12-04 19:21:54
问题 Hopefully this question is quick and painless I have a mvc view where i want to display either one of two values depending on an if statement. This is what I have in the view itself: <%if (model.CountryId == model.CountryId) %> <%= Html.Encode(model.LocalComment)%> <%= Html.Encode(model.IntComment)%> If true display model.LocalComment, if false display model.IntComment. This doesn't work as I get both values showing. What am I doing wrong? 回答1: Your if statement always evaluates to true. You

Mocking a MembershipUser

心已入冬 提交于 2019-12-04 19:05:13
问题 I'm currently developing an asp.net mvc 2 application which uses the default SqlMembershipProvider for authentication. I've implemented a controller method that reads the ProviderUserKey of the current user by calling Membership.GetUser().ProviderUserKey . Now I'm trying to write some test methods for this controller. To get rid of the dependancy on the static Membership class, I've created a thin wrapper and made my controller depend on the corresponding interface: public interface