asp.net-mvc-2

Why do we use HTML helper in ASP.NET MVC?

你。 提交于 2019-12-18 19:05:35
问题 Are there any good thing, best practice or profit we have after using the HTML helper in an ASP.NET MVC project? When I am trying to use them I found that I lose the speed I have with HTML and many difficulties I have whenever I use an HTML helper. Other [non-techie] persons can't understand what I write using Helper if I want to show them or they want to do something they need to spent more time on, even if they have working knowledge of HTML. If I use an HTML helper I lose the speed. When I

Why do we use HTML helper in ASP.NET MVC?

让人想犯罪 __ 提交于 2019-12-18 19:05:05
问题 Are there any good thing, best practice or profit we have after using the HTML helper in an ASP.NET MVC project? When I am trying to use them I found that I lose the speed I have with HTML and many difficulties I have whenever I use an HTML helper. Other [non-techie] persons can't understand what I write using Helper if I want to show them or they want to do something they need to spent more time on, even if they have working knowledge of HTML. If I use an HTML helper I lose the speed. When I

Get a form action/url with jquery

為{幸葍}努か 提交于 2019-12-18 18:48:23
问题 How do I get the action url from a form with jquery? 回答1: Get the form, ask for the action attribute: $('#myForm').attr('action'); 回答2: Need the full action url instead of just the basename? Generally it's better to use prop() instead of attr() when grabbing these sorts of values. (This prop() vs attr() stackoverflow post explains why.) However, in this instance, @JAAulde answer is exactly what I needed, but not might be what you need. You might want the full action url. Consider this html

Correct 404 message for a missing ASP.Net MVC controller

限于喜欢 提交于 2019-12-18 18:27:49
问题 I have an MVC 2 application that should always give a 'nice' 404 page. However currently I get a low level .Net one: "Server Error in '/sitename' Application..." I have a base controller that has a NotFound action that will render the nice 404 page. Missing actions are handled: protected override void HandleUnknownAction(string actionName) { this.NotFound(actionName).ExecuteResult(this.ControllerContext); } So a visit to {site}/ValidController/NotAnAction gets routed correctly. However a

Inline client side validation with MVC and jQuery

大兔子大兔子 提交于 2019-12-18 17:51:20
问题 I have setup a simple example to show a form inside a jquery UI dialog and wish to enable inline client side validation on that form I have then added the scripts to my master page <script type="text/javascript" src="<%: Url.Content( "~/_assets/js/jquery-1.4.3.min.js" )%>"></script> <script type="text/javascript" src="<%: Url.Content( "~/_assets/js/jquery.validate.min.js" )%>"></script> <script type="text/javascript" src="<%: Url.Content( "~/_assets/js/MicrosoftMvcJQueryValidation.js" ) %>"><

Howto automatically add a specific value from current route to all generated links?

岁酱吖の 提交于 2019-12-18 17:13:27
问题 I have site culture in URLs like this: routes.MapRoute( "Default", "{language}/{controller}/{action}/{id}", languageDefaults, languageConstraints) And it works like a charm with a little help from custom MvcHttpHandler that sets current thread's UI culture on every request based on route value. My problem is how do I automatically add the language route value from current request to all outgoing links? E.g. when page /EN/Foo/Bar is requested, I would like this <%=Html.ActionLink( "example

Save image to database with ASP.NET MVC

南笙酒味 提交于 2019-12-18 17:02:19
问题 I am trying to save image to database with Create method. but when try this code, I get this error: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters.* I am very beginner to MVC. I will really appreciate for the response, Many thanks in advance. [Authorize] [HttpPost] public ActionResult Create(Customers saveCustomer) { try { // TODO: Add insert logic here var upload =

Where is the right version of MicrosoftMvcJQueryValidation.js for MVC 2 beta 2?

邮差的信 提交于 2019-12-18 16:57:44
问题 MicrosoftMvcJQueryValidation.js is used by ASP.NET MVC 2 for client side validation. Having problems with this file just not working properly and wondering if I have the wrong version. The version I am using came from the source for futures. MicrosoftMvcJQueryValidation.js 5,626 bytes 11/17/09 10:43:12am There are two reasons i think i have the wrong version : 1) I actually have to call this code to get the validation routine working at all. This is because the default client validation

ASP.NET MVC - Unit testing RenderPartialViewToString() with Moq framework?

不羁的心 提交于 2019-12-18 16:49:36
问题 I'm using this helper method to turn my PartialViewResult into string and returning it as Json - http://www.atlanticbt.com/blog/asp-net-mvc-using-ajax-json-and-partialviews/ My problem is that I'm using Moq to mock the controller, and whenever I run unit test that uses this RenderPartialViewToString() method, I got the "Object reference not set to an instance of an object." error on ControllerContext. private ProgramsController GetController() { var mockHttpContext = new Mock

MVC2 TextBoxFor value not updating after submit?

a 夏天 提交于 2019-12-18 14:54:12
问题 This is a really strange behavior, and I've set up some demo code to try to figure out what's going on. Basically have a a two actions and a single view. The first action sends an empty model to the view, the section action recieves the model, alters its contents and sends it back to the same view. The wierdness is, in the view, the Model seems to have the updated values in it, but when I do an Html.TextBoxFor(x => x.PropertyNameHere) it renders a textbox with the unaltered value in it. lol..