asp.net-mvc-2

Validation not working in partial view

一个人想着一个人 提交于 2019-12-10 14:58:18
问题 I have an Index page which has two partial views: login and register.I am using data model validation. Login.cshtml @model Project.ViewModel.UserModel <div style="position:inherit;"> @using (Html.BeginForm("_Login", "account")) { @Html.ValidationSummary(true) <div class="label">@Html.Label("Username")</div> <div class="field">@Html.TextBoxFor(m => m.Username)</div> <div class="error">@Html.ValidationMessageFor(model => model.Username)</div> <div class="label">@Html.Label("Password")</div>

How do the httppost, httpput etc attributes in ASP.NET MVC 2 work?

荒凉一梦 提交于 2019-12-10 13:07:56
问题 In ASP.NET MVC 2, a couple of new action filter attributes were introduced, as "shorthand" for attributes in ASP.NET MVC 1; for example, applying the HttpPostAttribute does the same thing as applying [AcceptVerbs(HttpVerbs.Post)] to an action method. In addition, with the more verbose syntax, it is possible to combine different methods, in order to allow for example both Post and Delete . Now I'm wondering: how do the new attributes work? If I apply both [HttpPost] and [HttpDelete] , will ASP

Problems with RedirectToAction MVC2 - Cannot implicitly convert type 'System.Web.Mvc.RedirectToRouteResult' to 'System.Web.Mvc.ViewResult'

只谈情不闲聊 提交于 2019-12-10 12:31:55
问题 I am receiving this error when trying to use RedirectToAction, can anyone offer any advice on why this could be occuring, ive used this before without any problems, i must be missing something. Cannot implicitly convert type 'System.Web.Mvc.RedirectToRouteResult' to 'System.Web.Mvc.ViewResult' [HttpPost] public ViewResult Edit(Customer customer) { if (ModelState.IsValid) { customersRepository.SaveCustomer(customer); TempData["message"] = customer.CustomerName + " has been saved."; return

HTML Agility Pack - How can append element at the top of Head element?

筅森魡賤 提交于 2019-12-10 12:31:49
问题 I'm trying to use HTML Agility Pack to append a script element into the top of the HEAD section of my html. The examples I have seen so far just use the AppendChild(element) method to accomplish this. I need the script that I am appending to the head section to come before some other scripts. How can I specify this? Here's what I'm trying: HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load(filePath); HtmlNode head = htmlDocument.DocumentNode.SelectSingleNode("/html/head");

How to perform an update using ObjectContext

帅比萌擦擦* 提交于 2019-12-10 12:23:46
问题 I am using EF4 in my ASP.NET MVC 2 web application. I am attempting to save data to a database. It is fairly straightforward to add new data to a database. I'm doing it something like this: PeopleEntities entities = ObjectContextFactory.GetPeopleEntities(); entities.People.AddObject(person); // The Person object created from user input. entities.SaveChanges(); However, this has the unfortunate side-effect of always saving a new object to my database. I do need this functionality (of course),

implementing ValidationMessageFor

泪湿孤枕 提交于 2019-12-10 12:04:40
问题 I was working on migrating MVC1 app to MVC2 today and i have come across a problem while changing the ValidationMessage to ValidationMessageFor implementation. The below is the selectlist in my View <%=Html.DropDownListFor(model => model.SecurityQuestions[0].Question, "Some Security question", new { @class = "form_element_select" })%> The below code works fine and i can see the validation message came from modelstate. <%= Html.ValidationMessage("SecurityQuestions_0__Question")%> but this one

How to use IN operator in Linq?

不羁岁月 提交于 2019-12-10 11:48:38
问题 Query: Select * from pu_Products where Part_Number in ('031832','027861', '028020', '033378') and User_Id = 50 and Is_Deleted = 0 The above mentioned query is in SQL and i need the query might be converted into Linq. Is there any option using the "IN" operator in Linq?. can you convert above mentioned query into Linq? 回答1: dbContext.Products .Where(p => (new string[] {"031832","027861","028020","033378"}) .Contains(p.Part_Number) && p.Is_Deleted == false); 来源: https://stackoverflow.com

ASP.NET MVC 2 Beta single-project Area registration getting HTTP 404

不打扰是莪最后的温柔 提交于 2019-12-10 11:46:23
问题 I'm trying to get ASP.NET MVC 2 single-project area registration to work. Tried with Preview 2 and now with Beta version with no luck. I used the "Add area" dialog to create a "NewsModule" area. Created a NewsModuleController inside it and an Index view for it. The route registration for this Area looks like this: context.MapRoute( "NewsModule_default", "NewsModule/{action}/{id}", new { action = "Index", id = "", controller = "NewsModule", area = "NewsModule" } ); I added the AreaRegistration

How EditorFor set ID and Name html attributes on form elements

非 Y 不嫁゛ 提交于 2019-12-10 11:45:56
问题 I have few layers of nesting custom user controls: RegisterUser.aspx <%@ .... Inherit="System.Web.Mvc.ViewPage<RegisterUserViewModel>" ... <%= Html.EditorFor(m => m.Details) %> ... UserDetails.ascx <%@ .... Inherit="System.Web.Mvc.ViewUserControl<UserDetails>" ... <%= Html.EditorFor(m => m.BirthDate) %> <!--BirthDate is of type DateTime--> ... and I have declared DateTime.ascx in Shared/EditorTemplates <%@ .... Inherit="System.Web.Mvc.ViewUserControl<dynamic>" ... <input type="text" id="???"

Ninject giving NullReferenceException

被刻印的时光 ゝ 提交于 2019-12-10 11:27:43
问题 I'm using asp.net MVC 2 and Ninject 2. The setup is very simple. Controller calls service that calls repository. In my controller I use inject to instantiate the service classes with no problem. But the service classes don't instantiate the repositories, giving me NullReferenceException. public class BaseController : Controller { [Inject] public IRoundService roundService { get; set; } } This works. But then this does not... public class BaseService { [Inject] public IRoundRepository