asp.net-mvc-2

CultureInfo issue with Modelbinding double in asp.net-mvc(2)

笑着哭i 提交于 2019-12-03 14:11:11
In my Jquery script I post two doubles using the browser's CultureInfo (en-UK) that uses the . as a fraction separator. My MVC app is running on a server with locale nl-BE using the , as a fraction separator. [AcceptVerbs(HttpVerbs.Post)] public JsonResult GetGridCell(double longitude, double latitude) { var cell = new GridCellViewModel { X = (int)Math.Round(longitude, 0), Y = (int)Math.Round(latitude, 0) }; return Json(cell); } The modelbinding fails because of the parsing issue. I think it would be best to have my javascript set to en-UK and the same for the modelbinding in my MVC app. But I

ASP.NET MVC AJAX with HTML.ValidationMessageFor

前提是你 提交于 2019-12-03 14:05:43
I'm used to the ASP.NET Webforms easy way of doing AJAX with UpdatePanels. I understand the process is much more artisanal with MVC. In a specific case, I'm using Data Annotations to validate some form inputs. I use the HTML.ValidationMessageFor helper to show an error message. If I want to use AJAX to post this form and show this error message, what would be the process? Is it possible to keep the HTML.ValidationMessageFor and make it work with AJAX? Thank you. This article might be helpful: ScottGu's blog: ASP.NET MVC 2: Model Validation . The validation used in MVC can be both client and

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

为君一笑 提交于 2019-12-03 14:03:31
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 replace ampersand in the URL returned from Url.Action with an escaped ampersand. Is there a built in or

How to implement historical versioning?

北慕城南 提交于 2019-12-03 13:54:45
问题 We are in the early stages of building a large C# MVC2 app (we also employ Sharp architecture and Nhibernate as part of the ecosystem) on SQL 2008 R2, and one of the requirements is that all database row versions are accessible for a given period of history. We have toyed with the idea of a layout similar to: id (PK) recordId versionId and having each edit to a record result in a new record being created with the same recordId and an incremented versionId. Record display would then be done

Setting visibility of a textbox in MVC3 Razor view engine

╄→гoц情女王★ 提交于 2019-12-03 13:46:04
I am new to MVC 3, razor view engine. I want to set the visibility of a textbox at runtime as per the value in my viewmodel. But the below code is not working. <td> @Html.TextBox("CompanyName", "", new { visible = "false" }) </td> Once above code starts working, I could place @Model.EnableCompanyName in place of hardcoded "false". So please help me in rectifying the above code. This will change the display type based on your bool Model.EnableCompanyName :) Hope it helps! @{ String displayMode = (Model.EnableCompanyName) ? "inline" : "none"; @Html.TextBox("CompanyName", "", new { style =

ASP.NET MVC Render View to a string for emailing

孤人 提交于 2019-12-03 13:43:14
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 can't work out how to invoke a view. Any suggestions would be great! Thanks in advance. Gifster

Read OAuth2.0 Signed_Request Facebook Registration C# MVC

一个人想着一个人 提交于 2019-12-03 13:40:50
问题 My question is very similar this but I guess I need to take it one step further. Facebook says "The data is passed to your application as a signed request. The signed_request parameter is a simple way to make sure that the data you're receiving is the actual data sent by Facebook." After a user has logged into my asp c# MVC site and clicked "Register", the redirect-url is http://site/account/register. At that point (the post to the account/register control), I would like to gather the user's

Proper error handling in ASP.NET MVC2

陌路散爱 提交于 2019-12-03 13:29:24
问题 I have an override OnException(ExceptionContext filterContext) in my base controller to catch the app during any errors, and then log them. The problem I'm getting in my app is this particular method is fired off four times for certain errors. I'll walk you through a scenario: Let's say i navigate to: http://localhost:180/someController/someAction?someId=XX And I have poor object handling in my code. The Id passed in is an invalid one, and it retrieves some null object, I then, bc of my bad

Display datetime model property as Short date time string

a 夏天 提交于 2019-12-03 13:07:23
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-dimension array index, or single-parameter custom indexer expressions. What is the correct way to handle

MVC 2 AntiForgeryToken - Why symmetric encryption + IPrinciple?

怎甘沉沦 提交于 2019-12-03 13:03:14
We recently updated our solution to MVC 2, and this has updated the way that the AntiForgeryToken works. Unfortunately this does not fit with our AJAX framework any more. The problem is that MVC 2 now uses symmetric encryption to encode some properties about the user, including the user's Name property (from IPrincipal ). We are able to securely register a new user using AJAX, after which subsequent AJAX calls will be invalid as the anti forgery token will change when the user has been granted a new principal. There are also other cases when this may happen, such as a user updating their name