asp.net-mvc-2

How do I transfer ViewModel data between POST requests in ASP.NET MVC?

青春壹個敷衍的年華 提交于 2019-12-14 03:53:33
问题 I have a ViewModel like so: public class ProductEditModel { public string Name { get; set; } public int CategoryId { get; set; } public SelectList Categories { get; set; } public ProductEditModel() { var categories = Database.GetCategories(); // made-up method Categories = new SelectList(categories, "Key", "Value"); } } Then I have two controller methods that uses this model: public ActionResult Create() { var model = new ProductEditModel(); return View(model); } [HttpPost] public

Post with MVC 2, including values outside of form

自作多情 提交于 2019-12-14 03:10:52
问题 I'm pretty new to MVC 2 and I'm having problems figuring out how to post values that lies outside the form. This is my code very simplified: <input type="text" id="TextboxOutsideForm"/> <% using (Html.BeginForm("Edit", "Home", FormMethod.Post)) {%> <%: Html.ValidationSummary(true) %> <%: Html.TextBoxFor(model => model.Stuff) %> <input type="submit" value="Save" /> <% } %> TextboxOutsideForm can be changed by the user and when pushing save I want to include the value from this control to the

MVC 2 how to go to url without redirecting?

我与影子孤独终老i 提交于 2019-12-14 03:08:59
问题 Is there a way to go to a url without redirecting to it? Basically I want to call a url from within my application in the background so it can logout a reliant party. Appreciate the help. 回答1: What you are trying to do does not compete us to answer as it's directly related to your own Authentication implementation. A normal ASP.NET Authentication based in Forms Authentication you will need always to lunch the url from a browser as it is there that relies the Authentication given. You can give

make checkbox disabled in asp.net mvc 2 and jquery

混江龙づ霸主 提交于 2019-12-14 03:05:41
问题 i got a checkbox that i would like to be disabled ? i am using asp.net mvc 2 and jquery. <%= Html.EditorFor(p=>p.flag) %> public class MyModel { public bool flag {get;set;} } 回答1: you can either use jquery to disable your checkbox using $('#flag').attr('disabled', true); or if you want to do it on server side you have to fall back to checkboxfor helper like <%:Html.CheckBoxFor(x => x.flag, new { disabled = "disabled" }) %> or you can write your own editor template that can consume

Pass collection of enums to ASP.NET MVC ActionMethod

喜你入骨 提交于 2019-12-14 02:44:03
问题 Is there a way to pass a collection of Enums to an ActionMethod (on a GET) automatically? For example, if I have the following enum definition: enum DaysEnum {Sat, Sun, Mon, Tue, Wed, Thu, Fri}; and, I have an ActionMethod definition of: ActionResult SampleActionMethod ( List<DaysEnum> days) Is there a way I could render, in a View, a URL that would pass in a collection of DayEnums. Something like: var someDays = new List<DaysEnum> {DaysEnum.Sat, DaysEnum.Sun, DaysEnum.Mon}; Url.Route(new {

How can I disable a form's submit button if there are DataAnnotation validation errors?

老子叫甜甜 提交于 2019-12-14 02:30:08
问题 I've attempted binding to the change event of all inputs in the form, and checked to see if there are any validation messages on the page. The problem is that validation seems to occur after the change event, so I am checking before the errors appear on the page. I'm looking for some way to run my script after the client-side validation takes place. I'm using MVC 2 with DataAnnotation attributes on my VM. 回答1: Here's something I just hacked together that wraps the original parseElement and

In ASP.NET MVC2, convert time user's timezone. How to get timezone info? [closed]

南楼画角 提交于 2019-12-13 22:31:48
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I stored datetime into database then i retrieve the values.. My server db is located other country. so when the value is retrieve it is taking other country date and time.. I tried in controller as follow, if (item.CreatedDate == null) { item.CreatedDate = DateTime.Now; var timeZone = TimeZoneInfo

C#3.5 MVC2 routing skip optional param

让人想犯罪 __ 提交于 2019-12-13 20:34:05
问题 Here I have: routes.MapRoute( "test", // Route name "DataWarehouse/Distribution/{category}/{serialNo}", new { controller = "DataWarehouse", action = "Distribution", category= UrlParameter.Optional, serialNo = UrlParameter.Optional } ); Category and serialNo are both optional params. When the routing is like: DataWarehouse/Distribution/123 , it always treat 123 as the value for category. My question is how I can make it to know the 1st param could be either category or serialNo, i.e.

Error in MVC contribgrid regarding identifier excepted

梦想的初衷 提交于 2019-12-13 20:08:51
问题 i am using mvc 2 and mvc contribgrid I am Getting error as "Newline is constant","identifier expected",";excepeted" here is my coding <table cellpadding="0" cellspacing="0" width="100%"> <% if (ViewData["CustomerInfoList"] !=null && ((List<SaasModel.CustomerInfo>)ViewData["CustomerInfoList"]).Count()>0) { %> <tr> <td> <% Html.Grid((List<SaasModel.CustomerInfo>)ViewData["CustomerInfoList"]).Columns( column=> { column.For(col=>col.CustomerName).Named("Name"); column.For(col=>col.CompanyName)

MVC2 Client Validation isn't working when getting form from ajax call

瘦欲@ 提交于 2019-12-13 16:01:18
问题 I'm trying to use MVC2 client-side validation in a partial view that is rendered via $.get. However, the client validation isn't working. I'm not quite sure what the deal is. [Required(ErrorMessage = "Email is required")] public string Email { get; set; } <% using ( Ajax.BeginForm( new AjaxOptions { Confirm = "You sure?" } ) ) { %> <%: Html.TextBoxFor( m => m.Email, new { @class = "TextBox150" } )%> <%= Html.ValidationMessageFor( m => m.Email )%> <input type="submit" value="Add/Save" style=