asp.net-mvc-2

End Session on MVC

元气小坏坏 提交于 2020-01-25 08:54:05
问题 I have this question you probably know the answer... My app is already functional and working fine. Whenever a user authenticates the app updates its model with the LastLoginDate, and when the user logs out the app updates its model with the LastLogOutDate. This works fine while the user keeps clicking on the logout link. However, if the user closes the windows the LastLogOut value never gets updated, and what happens is that Administrator sees users online that are not. The same thing

Replacing ViewModels with Tuples

醉酒当歌 提交于 2020-01-25 08:31:05
问题 I've just started on a new project which currently contains a fair few ViewModel DTO classes. I'm wondering whether it would be useful and even good practice to replace many of these DTOs with Tuples and to use that as my method of transfering a bunch of objects to my views. What do you think? Is this a correct usage of the tuple or am I off the mark here? 回答1: Usually view models have metadata associated with them which among other allows you to perform validation and integrates with editor

Updating Html.Dropdownlists using JQuery

我只是一个虾纸丫 提交于 2020-01-24 21:41:05
问题 I found this solution on here How to update strongly typed Html.DropDownList using Jquery and am trying to implement it, but something is bugged in it. $(function() { $('#cid').change(function() { var selectedCompany = $(this).val(); var ddl = $("#foid"); $.post("/TimeTracking/FilterFieldOffices", { companyId: selectedCompany }, function (data) { $(ddl).loadSelect(data); }); }); }); (function($) { $.fn.emptySelect = function() { return this.each(function() { if (this.tagName == 'SELECT') this

Custom property: gotta be something obvious I'm doing wrong

萝らか妹 提交于 2020-01-24 18:33:23
问题 I have been adding partial classes of my different entities to add various useful methods without issue. Attempting to add properties appears to be straightforward based on examples that I've seen, but mine are failing miserably. Updated example: public List<Friend> FriendsInGoodStanding { get { using (var context = new GarbageEntities()) { var a = context.Friends.Include("aspnet_User1").Where(f => f.UserID == this.UserId && f.Blocked == false).ToList(); var b = context.Friends.Include(

MVC2 --> MVC3 Upgrade

蹲街弑〆低调 提交于 2020-01-24 02:53:13
问题 As today's MVC3 released, I would like to ask if anyone had experienced problems in upgrading from MVC2 to MVC3 (without changing anything in the views) . I'm currently using EF4, Telerik extensions Should I upgrade, or should I wait ? 回答1: The lead developer on the project I'm currently on installed and upgraded MVC2 to MVC3 RC, and the project and we're using EF4 and Telerik. We updated from RC to the release this morning and discussed the update from MVC2 to MVC3 RC. After installation, he

Get the selected drop down list value from a FormCollection in MVC

瘦欲@ 提交于 2020-01-24 02:27:21
问题 I have a form posting to an action with MVC. I want to pull the selected drop down list item from the FormCollection in the action. How do I do it? My Html form: <% using (Html.BeginForm()) {%> <select name="Content List"> <% foreach (String name in (ViewData["names"] as IQueryable<String>)) { %> <option value="<%= name %>"><%= name%></option> <% } %> </select> <p><input type="submit" value="Save" /></p> <% } %> My Action: [HttpPost] public ActionResult Index(FormCollection collection) { /

Invalidate the whole output cache in asp .net MVC 2

試著忘記壹切 提交于 2020-01-23 17:39:28
问题 How is it possible to invalidate the whole output cache in asp .net mvc 2? 回答1: AFAIK this is not possible. You can only invalidate specific actions that might have been cached by decorating them with the [OutputCache] attribute. HttpResponse.RemoveOutputCacheItem(Url.Action("Index", "Products")); 回答2: While I don't know if there is a way to do it in code, still recycling the worker process might invalidate the server cache. If this is true then you might even do it in code by having code to

ASP.NET MVC - Update Pre-compiled Razor View file Live in Production

梦想的初衷 提交于 2020-01-22 22:56:18
问题 I was wondering if the following is possible : Precompile the Razor views with our MVC app by turning on the project setting in visual studio. Deploy the app to production. Then at a later stage, update the views by overwriting the existing *.cshtml files in production without recycling the app pool or re-compiling the project and re-deploying the build.? 回答1: Yes you can do this. The view engine will recompile all the files in each directory into a separate DLL into a file like this C:

How to render a model property of string type as checkbox in ASP.NET MVC

╄→гoц情女王★ 提交于 2020-01-22 13:13:05
问题 I want to display a string type as checkbox on MVC view, but returns it as string type on HTTP post. The problem is that it returns false on HTTP Post. Below is my code: View: @model List<Car> foreach(var car in Model){ bool isFourWheel = false; if(bool.TryParse(car.IsFourWheel, out isFourWheel){ @Html.CheckBox("IsFourWheel", isFourWheel); //need to be rendered as checkbox, but returns string type on HTTP POST } } Model: public class Car { public string IsFourWheel { get; set; } //bad naming,

How do I display a datatable in asp.net mvc 2?

与世无争的帅哥 提交于 2020-01-17 02:38:26
问题 I am running a dynamically built SQL statement and putting the results in a datatable. I then need to display these results as a table in a partial view. I would normally create a List<> object and strongly type it to the page, but in this case I do not know what the final sql will be, since it is built by the user at run time. So, how can I display the data in a datatable when I do not know what is in it? Also is there a better way to do this than in a datatable? Thanks 回答1: As you are