asp.net-mvc-2

ViewDataFactory and strongly typed master pages

こ雲淡風輕ζ 提交于 2019-12-05 04:31:51
问题 Im trying to get my strongly typed master page to work in my ASP MVC 2.0 application. I have come far with the help of these two posts: Passing data to Master Page in ASP.NET MVC Strongly Typed ASP.Net MVC Master Pages Problem is that im not sure how to get that ViewDataFactory code to work, this is my code: BaseController.cs public class BaseController : Controller { private IPageRepository _repPage; public BaseController(IPageRepository repPage) { _repPage = repPage; } protected T

How do I create a httppost getting same parameters from httpget?

跟風遠走 提交于 2019-12-05 04:18:37
I have a controller to show up a model (User) and want to create a screen just with a button to activate. I don't want fields in the form. I already have the id in the url. How can I accomplish this? You could use a hidden field inside the form: <% using (Html.BeginForm()) { %> <%= Html.HiddenFor(x => x.Id) %> <input type="submit" value="OK" /> <% } %> or pass it in the action of the form: <% using (Html.BeginForm("index", "home", new { id = RouteData.Values["id"] }, FormMethod.Post)) { %> <input type="submit" value="OK" /> <% } %> Use [ActionName] attribute - this way you can have the URLs

ASP.NET MVC: generating action link with custom html in it

别等时光非礼了梦想. 提交于 2019-12-05 04:10:27
How can I generate action link with custom html inside. Like following: <a href="http://blah-blah/....."> <span class="icon"/> New customer </a> You can use the UrlHelper class : <a href="<% =Url.Action("Create","Customers") %>"> <span class="icon"/> New customer </a> The MSDN link is here : http://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.aspx 来源: https://stackoverflow.com/questions/3879547/asp-net-mvc-generating-action-link-with-custom-html-in-it

Convert MVC 2 ASPX into MVC 4 Razor view engine

那年仲夏 提交于 2019-12-05 04:02:39
I am currently working on MVC 2 with visual studio 2010 and view engine as ASPX kind of project. So I have decided to move with Visual studio 2012 with MVC 4 and view engine as Razor . So could I achieve above task.If so How ? I would like to hear your experience for similar kind of situation. Note : My project is a large one. Scott Create a new MVC4 project in Visual Studio 2012 and add source files from your old solution to your new solution one at a time. Moving from MVC3 to MVC4 is easier with a new solution, I have to imagine that going from 2 -> 4 would be even more complex to try to

No styles / images on asp.Net MVC 2 application

笑着哭i 提交于 2019-12-05 03:37:36
Greetings i have a little problem with my ASP MVC application. On my local development server everything works just fine but when i try to publish the application to an IIS 7.0 server it just displays plain pages without any styles / markups / images. I put all those things in the /Content/ subfolder but when i try to access that folder on the production server it just returns me a 404 not found error. I set the IIS server up with .Net 4.0 and followed the deployment guide on here: http://www.asp.net/learn/mvc/tutorial-08-cs.aspx All views / controllers / classes seem to work just fine, the

separate numbers by comma with asp.net mvc

霸气de小男生 提交于 2019-12-05 03:27:55
I am working on an MVC2 appication. I use data annotations to validate data (both client side and server side). I have several fields in my model that only allows decimal values. As soon as a user types a decimal values I want it to be converted to comma seperated more readable format. For instance 1200 should be formatted to 1,200 while 500 should stay as it is. Here is my model: public virtual GrossFee? Fee { get; set; } And here is how it is on the view: %: Html.TextBoxFor(model => model.GrossFee)%> Any ideas regarding this will be highly appreciated. Thanks! Instead of the Html.TextBoxFor

POST Json without model and Ajax

不想你离开。 提交于 2019-12-05 03:24:28
问题 For now, I just want to use HTTP POST to send json to asp.net mvc2 controller. Since the JSON is actually a list of JSON objects, and each of them has different fields & length, so it hard for me to make up a input model. So I want to know is there a way for me to post JSON without model/ajax to a controller in ASP.NET MVC2? 回答1: Building on @Brian's answer, we have done exactly this. Keep in mind this is Jquery 1.4.2 This is broken out a bit and could be simplified, but it is using callbacks

FormsAuthentication.SetAuthCookie mocking using Moq

余生长醉 提交于 2019-12-05 03:23:40
Hi i'm doing some unit test on my ASP.Net MVC2 project. I'm using Moq framework. In my LogOnController, [HttpPost] public ActionResult LogOn(LogOnModel model, string returnUrl = "") { FormsAuthenticationService FormsService = new FormsAuthenticationService(); FormsService.SignIn(model.UserName, model.RememberMe); } In FormAuthenticationService class, public class FormsAuthenticationService : IFormsAuthenticationService { public virtual void SignIn(string userName, bool createPersistentCookie) { if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.",

HttpApplicationState not available in an MVC controller

痞子三分冷 提交于 2019-12-05 03:06:41
I'm using MVC2 and VS2010 developing a website and need to use Application State global values. I can set a value like 'Application["hits"]=0;' in Global.asax but when trying to use the same in an MVC controller always get the following error: The name 'Application' does not exist in the current context I have also tried using in the Global.asax in order to define a global variable but it triggers the following error: A namespace cannot directly contain members such as fields or methods I'm looking for a way to define global Application State values that are available within all controllers of

How do I use Ninject with ActionResults while making the controller IoC-framework-agnostic?

送分小仙女□ 提交于 2019-12-05 02:46:27
问题 Nearly all of the Ninject examples I've seen explain how to use it with ASP.NET MVC, which will automatically inject dependencies into controllers. How would I use Ninject manually though? Let's say I have a custom ActionResult: public class JsonResult : ActionResult { [Inject] public ISerializer Serializer { get; set; } public JsonResult(object objectToSerialize) { // do something here } // more code that uses Serializer } Then in my controller, I'm using JsonResult in a method like this: