asp.net-mvc-2

Child actions are not allowed to perform redirect actions - error while working with ASP.NET MVC 2 and Razor

人盡茶涼 提交于 2019-12-01 17:14:06
问题 In _Layout.cshtml file I have following entry: @Html.Action("LoadPagesStructure", "Page") Inside PageController class, LoadPagesStructure methos looks following: [ChildActionOnly] /* this attribute indicates that an action should not be invoked as a result of a user request (by url) */ public ActionResult LoadPagesStructure() { ViewModel.Pages = new List<string>() {"page1", "page2", "page3"}; return View(); } Finally, my LoadPagesStructure.cshtml view looks like below: @inherits System.Web

ASP MVC: Custom Validation Attribute

纵饮孤独 提交于 2019-12-01 16:49:20
问题 I'm trying to write my own Custom Validation attribute but I'm having some problems. The attribute I'm trying to write is that when a user logs in, the password will be compared against the confirmation password. namespace Data.Attributes { public class ComparePassword : ValidationAttribute { public string PasswordToCompareWith { get; set; } public override bool IsValid(object value) { if (PasswordToCompareWith == (string)value) { return true; } return false; } } Now my problem is when i'm

JSON, ASP.NET MVC - MaxJsonLength exception

时光怂恿深爱的人放手 提交于 2019-12-01 15:47:20
问题 I am just trying to shift some comma separated numbers to the frontend: [AcceptVerbs(HttpVerbs.Get)] public JsonResult GetSquares() { var result = new JsonResult(); result.JsonRequestBehavior = JsonRequestBehavior.AllowGet; IList<double> list = new List<double>(); ... result.Data = list; return result; } This works fine as long as there are only a few numbers. Unfortunately, I have to shift lots of numbers occasionally and get a MaxJsonLength exception. I tried several suggestions to overcome

Optional routing parameter with constraint in ASP.NET MVC 2?

ⅰ亾dé卋堺 提交于 2019-12-01 15:20:42
问题 If I have a route like this: routes.Add(new Route("{controller}/{page}", new RouteValueDictionary { { "page", UrlParameter.Optional } }, new RouteValueDictionary { { "page", @"[Pp]age\d+" } }, new MvcRouteHandler() )); Then the route doesn't match when {page} is missing, however if I remove the constraint it matches. Is this a bug or a feature? 回答1: It's a feature: how can the constraint match if the parameter if optional? You might either want to set the default value for "page" to "Page1"

How to show/hide an area within Razor View in ASP.NET MVC programmatically

微笑、不失礼 提交于 2019-12-01 15:04:05
I want to programmatically show/hide a group of fields (label, textfield, checkbox) on Razor view (.cshtml), based on a model value. The model is access to the view. Thanks In your Razor View cshtml: @if(Model.RevealSecretPlans) { <div> Giant frikkin laser </div> } This of course assumes RevealSecretPlans is a boolean 来源: https://stackoverflow.com/questions/6848055/how-to-show-hide-an-area-within-razor-view-in-asp-net-mvc-programmatically

The view '~/Views/Login/Login.aspx' must derive from ViewPage, ViewPage<TModel>, ViewUserControl or ViewUserControl<TModel>

只愿长相守 提交于 2019-12-01 14:25:17
So I am getting this error on ASP.NET mvc2 solutions that used to work fine. I had to install Visual Studio 2012 and was running low on disk space, so had to manually uninstall some Visual Studio 2010 functionalities which didn't seem to be completely necessary at the moment. Now whenever I try to debug an application which targets the 4.0 .NET framework I get this error. I tried re-installing Visual Studio and the .net framework, but it keeps kappening. I don't know what to do. Also, i tried what's stated in this question ( Getting the error "The view at '~/Views/Page/home.aspx' must derive

How to show/hide an area within Razor View in ASP.NET MVC programmatically

久未见 提交于 2019-12-01 13:52:43
问题 I want to programmatically show/hide a group of fields (label, textfield, checkbox) on Razor view (.cshtml), based on a model value. The model is access to the view. Thanks 回答1: In your Razor View cshtml: @if(Model.RevealSecretPlans) { <div> Giant frikkin laser </div> } This of course assumes RevealSecretPlans is a boolean 来源: https://stackoverflow.com/questions/6848055/how-to-show-hide-an-area-within-razor-view-in-asp-net-mvc-programmatically

jQuery Modal Window to Display a Table in MVC

放肆的年华 提交于 2019-12-01 13:39:43
Let me start of by saying that I am inexperienced with JavaScript. Here is what I want to do. When the user clicks "Show Details" on a row of data, they get a pop-up (modal?) window that has some data generated from another action within the MVC application. Where can I find an example of implementing something like this? Also, when a user clicks "Approve" on either this pop-up or on the original data row another pop-up will display with a form a person needs to fill out. Any direction will be greatly appreciated. First of all, you will need a DIV somewhere on your page - let say give it an id

sortable telerik grid + NHibernate, IQueryable and ASP.NET MVC

≯℡__Kan透↙ 提交于 2019-12-01 13:37:00
I am trying to get a telerik grid to work (paging works fine). My view code looks like this: @(Html.Telerik().Grid(Model) .Name("Grid") .Columns(columns => { columns.Bound(o => o.ItemName.Text).Title("Name"); }) .Pageable(pager => pager.PageSize(20)) .Sortable() ) My controller looks like this: public ActionResult Index(GridCommand command) { return View(BlaRepository.GetBlas(command.PageSize, command.Page)); } The repository looks like this: public IQueryable<Bla> GetBlas(int PageSize, int Page) { var query = (from e in Session.Query<Bla>() select e).AsQueryable(); return query.Skip((Page - 1

Using a custom MvcHttpHandler v2.0 Breaking change from 1.0 to 2.0?

爱⌒轻易说出口 提交于 2019-12-01 13:34:53
问题 I have a site where part is webforms (Umbraco CMS) and part is MVC This is the HttpHandler to deal with the MVC functionality: public class Mvc : MvcHttpHandler { protected override void ProcessRequest(HttpContext httpContext) { httpContext.Trace.Write("Mvc.ashx", "Begin ProcessRequest"); string originalPath = httpContext.Request.Path; string newPath = httpContext.Request.QueryString["mvcRoute"]; if (string.IsNullOrEmpty(newPath)) newPath = "/"; httpContext.Trace.Write("Mvc.ashx", "newPath =