asp.net-mvc-2

How to format a URL.Action() call in JQuery to set a link's href attribute?

旧街凉风 提交于 2020-01-04 06:44:18
问题 I need to set the href attribute of a link to point to a specific image, which has its id from the database set as its title. However, I am having trouble with trying to format the string to include a call to get the title attribute of the image. Here is the base string: $("#favoriteLink").hover(function() { $(this).attr("href", '<%: Url.Action("FavoriteWallpaper", "Wallpaper", new{wallpaperId='+$(this).children.attr("title")+'}) %>'); }); favoriteLink is a div and the child is just one image

MVC2 DataAnnotations validation with inheritance

泄露秘密 提交于 2020-01-04 06:31:08
问题 I have a .NET 2.0 class the properties of which are marked virtual.I need to use the class as a model in a MVC2 application. So, I have created a .NET 3.5 class inheriting from the .NET 2.0 class and added the DataAnnotations attributes to the overriden properties in the new class. A snippet of what I have done is below // .NET 2.0 class public class Customer { private string _firstName = ""; public virtual string FirstName { get { return _firstName; } set { _firstName = value; } } } // .NET

ModelState always valid

▼魔方 西西 提交于 2020-01-04 05:31:31
问题 I've got something seemingly very simple not working. I have got a model public class Name: Entity { [StringLength(10), Required] public virtual string Title { get; set; } } public class Customer: Entity { public virtual Name Name { get; set; } } a view model public class CustomerViweModel { public Customer Customer { get; set; } } a view <% using(Html.BeginForm()) { %> <%= Html.LabelFor(m => m.Customer.Name.Title)%> <%= Html.TextBoxFor(m => m.Customer.Name.Title)%> <button type="submit"

How to add meta tags on a master page for ASP.Net MVC 2

删除回忆录丶 提交于 2020-01-04 01:53:07
问题 I have a master page currently with the below for the title: <title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title> I've now realised I have to put meta tags in, would that be best done like so: <asp:ContentPlaceHolder ID="TitleContent" runat="server"> <title>Title</title> <meta name="Description" content=" ... add description here ... "> <meta name="Keywords" content=" ... add keywords here ... "> </asp:ContentPlaceHolder> OR <title><asp:ContentPlaceHolder ID=

ASP.NET MVC 2 - ViewData empty after POST

爷,独闯天下 提交于 2020-01-04 01:25:11
问题 I don't really know where to look for an error... the situation: I have an ASPX view which contains a form and a few input's, and when I click the submit button everything is POST'ed to one of my ASP.NET MVC actions. When I set a breakpoint there, it is hit correctly. When I use FireBug to see what is sent to the action, I correctly see data1=abc&data2=something&data3=1234. However, nothing is arriving in my action method. ViewData is empty, there is no ViewData["data1"] or anything else that

ModelBinder is not invoked

最后都变了- 提交于 2020-01-03 21:09:49
问题 Per my previous question, I implemented a model binder that maps /api/v1/widgets/1,2,3 to // WidgetsController.cs: public ActionResult Show(IEnumerable<int> idArgs) { } This was working for a while, but now it is not any longer. My ModelBinder is not even being invoked at all. When my action is invoked, idArgs has a value of the empty list, even if I set its default value to null in the route, which suggests to me that the default model binder thinks it's getting a value from somewhere. The

MVC2 - Consume RSS feed with RDF and namespace http://www.w3.org/1999/02/22-rdf-syntax-ns#'

陌路散爱 提交于 2020-01-03 18:34:13
问题 I' trying to read the feed for the Washington Departmene of Fish and Wildlife, and keep etting this error: The element with name 'RDF' and namespace 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' is not an allowed feed format. Here's the code from RssController: public virtual ActionResult Index() { string feedUrl = @"http://wdfw.wa.gov/news/newsrss.php"; using (XmlReader reader = XmlReader.Create(feedUrl)) { **SyndicationFeed rss = SyndicationFeed.Load(reader);** return View(rss); } } I've

C# Asp.net Membership.GetAllUsers order by email

耗尽温柔 提交于 2020-01-03 16:47:59
问题 I am using Membership.GetAllUsers() to get my user list. I would like to have the list returned sorted by email address as I need to flag some accounts with duplicate emails. Membership.GetAllUsers() seems to order by username by default. Is there a way to change this behavior? 回答1: If you can live with a generic list rather than a MembershipUserCollection : Membership.GetAllUsers().Cast<MembershipUser>().OrderBy(x => x.Email).ToList(); Use OrderBy(x => x.Email, StringComparer

The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects mvc 2

女生的网名这么多〃 提交于 2020-01-03 10:41:13
问题 I beginners to the entity framework, so please bear with me... How can I relate two objects from different contexts together? The example below throws the following exception: System.InvalidOperationException: The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects. [OwnerOnly] [HttpPost] [ValidateInput(false)] public ActionResult Create(BlogEntryModel model) { if (!ModelState.IsValid) return View(model); var entry = new

converting toList() throws exception Object must implement IConvertible

安稳与你 提交于 2020-01-03 05:19:48
问题 I am getting this exception " Object must implement IConvertible. " while converting rules to tolist(). below is my code var rules = from m in db.Rules select m; return rules.ToList().ToDataTable(); // exception occurs here I am using MySQL 6.3.6 ..the same code is working fine with MSSQL. I will be grateful if someone helps me in this regards Umair 回答1: Make sure the source type is convertible to the destination type. Probably the rules.ToList() don't match with you ToDataTable destination