asp.net-mvc-2

access database info in a partial view, .ascx that is included in Site.Master in asp.net mvc

不问归期 提交于 2019-12-12 05:28:36
问题 Hi i'm having problems with this. I am developing an asp.net mvc 2 application. I have a partial view menu.ascx defined. this gets included on all the pages of my site in the Site.Master masterpage. Now the thing is I want my menu to change according to the type of user. Here's what I did at first: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %> <li><%: Html.ActionLink("Home", "Index", "Home")%></li> <% ExtendedMemberShip.MemberShipUser user =

How To: Overwriting all Html.TextBox - ascx not called! Why?

笑着哭i 提交于 2019-12-12 05:12:46
问题 How can I add to ALL textboxes in ALL aspx sites, like: <%: Html.TextBoxFor(model => model.Firstname, new { style = "float: left; width: 4.1em;", maxlength = "4" })%> a javascript function without searching them and adding manually something like: new { onkeyup='Foo(this); return false;' } Idea: Writing an ascx like the following one! <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> <%: Html.TextBox( string.Empty, ViewData.TemplateInfo.FormattedModelValue, new { onkeyup

Custom validation rules for ASP.NET MVC2 Application

久未见 提交于 2019-12-12 05:00:48
问题 I am attempting to add validation to my application. I have some rules I need to check before allowing the information to be written to the database. I have the basic data validation added to the model, but I also need to make sure that if one field has a certain value, this other field is required. At one time the NerdDinner tutorial at asp.net covered that and I used that in the past for validation, but now I can't find that or any other example. Here is my model: public class DayRequested

How to get the form or div by name which the AJAX.BeginForm' onsuccess is called

萝らか妹 提交于 2019-12-12 04:58:45
问题 I have called Ajax.BeginForm inside a div element, so I want to get the div element which the form is in. i.e. I want an equivalent of function function1(event){ var table = $(event.target).parents("table"); } which can be used from the Ajax.beginform's onsuccess function. Can anyone help here? 回答1: It turned out that, within the onsuccess function, "this" refers to the form element. So I could easily use, $(this).find("mydiv"); or $(this).parent("table").find("mydiv"); 回答2: MVC4 seems to

Localization with separate Language folders within Views

半城伤御伤魂 提交于 2019-12-12 04:44:07
问题 I'm trying to have specific folders for each language in Views. (I know this isn't the best way of doing it but it has to be this way for now) e.g. /Views/EN/User/Edit.aspx /Views/US/User/Edit.aspx These would both use the same controller and model but have different Views for each language. In my Global.asax.cs I have: routes.MapRoute( "Default", // Route name "{language}/{controller}/{action}/{id}", // URL with parameters new { language = "en", controller = "Logon", action = "Index", id =

Database permissions in MVC with NHibernate

爱⌒轻易说出口 提交于 2019-12-12 04:41:07
问题 I'm working on an intranet MVC web application, using Fluent NHibernate. As everyone knows, creating the necessary ISessionFactory is heavy, and therefore should be done only once. Hence, I create it in the Global.asax file during Application_Start , then cache it in the application for future use. The problem is that I only want to give access to users who already have permissions over the database. This could theoretically be solved by defining Integrated Security=SSPI in the connection

EF4.0 - Is there a way to see what entities are attached to what ObjectContext during debugging?

☆樱花仙子☆ 提交于 2019-12-12 04:38:39
问题 This is in continuation with my problem here. I'm trying to use the solution Julie Lerman gave me a few months ago. I'm currently using the following to generate a new Game entity pre-attached to my ObjectContext: Game game = _gameRepository.GetGame(formData.GameID); AutoMapper.Mapper.Map<AdminGameEditModel, Game>(formData, game); In the repository, I try to attach the Game to the OC with its state set to 'Added' like she suggested by doing the following: public Game GetGame(int id) { if (id

How to fix conversion error in MVC2 dropdownlist

*爱你&永不变心* 提交于 2019-12-12 04:35:47
问题 I tried simple dropdownlist in ASP.NET MVC2 but got error below from tryupdatemodel. How to fix this, everthing looks correct ? view: <%= Html.DropDownList("Post24DeliveryPlaces", Model.DeliveryPlace)%> model: public IEnumerable<SelectListItem> Post24DeliveryPlaces { get; set; } public string DeliveryPlace { get; set; } result: System.InvalidOperationException: The parameter conversion from type 'System.String' to type 'System.Web.Mvc.SelectListItem' failed because no type converter can

Replacement for ITemplate in MVC?

倾然丶 夕夏残阳落幕 提交于 2019-12-12 04:32:25
问题 I am currently running a website, i use a control that inherits from ITemplate to wrap all my usercontrols in. basically what it is, is a table with a nice border, and i am able to dump anything in there, so if i change the container template, all the containers accross the site changes... I am now in the process of rebuilding the entire application using MVC 2, does anyone know of a way i can achieve the same "Container" like template in MVC? 回答1: There would be several ways to do this in

ASP.NET MVC 2 Model partial binding

泄露秘密 提交于 2019-12-12 04:23:57
问题 My problem is that I want to partially edit my model - to display 2 fields and to edit another 2 fields for example. When POST happens, returned model contains only the fields that are editable, other fields that I use only to display are NULL. How to fix this, on POST to be returned model with all fields, because on ERROR when I return this model and fields are NULL is not so good? 回答1: The model binder binds the form values only to model properties that have a setter. Depending on what you