asp.net-mvc-3

ASP.NET MVC: Is Controller created for every request?

狂风中的少年 提交于 2020-01-26 10:17:26
问题 Very simple question: Are controllers in ASP.NET created for every HTTP request, or are they created at application startup and reused throughout requests? Will the controller be created only for a particular HTTP request? If my previous assumptions are correct, can I depend on it? I want to create database context (Entity Framework) that will live only for one request. If I create it as a property initialized in controller's constructor, is it granted that new instance of context will be

How to get current user timezone in c#

陌路散爱 提交于 2020-01-26 09:44:12
问题 I am building an application in MVC3 and when a user comes into my site I want to know that user's timezone. I want to know how to do this in c# not in javaScript? 回答1: As has been mentioned, you need your client to tell your ASP.Net server details about which timezone they're in. Here's an example. I have an Angular controller, which loads a list of records from my SQL Server database in JSON format. The problem is, the DateTime values in these records are in the UTC timezone, and I want to

How can i prevent User click the button to submit form if specify field is not valid?

ぃ、小莉子 提交于 2020-01-25 10:39:25
问题 I have a jquery function to check valid data on UsernameTextbox in my View. I want to prevent User click on the Register button until this field valid. Disable button is it the best method? I just want when the value is not valid, user click on button just focus to the UsernameTextbox filed? Update Code: Here is my Model : [Required] [Remote("CheckUsername", "Account", ErrorMessage = "Username already exits.")] public string Username { get; set; } and Controller with GET method: [HttpGet]

ID Being Rendered As Null In A Typed Razor View

纵饮孤独 提交于 2020-01-25 09:48:23
问题 This is really weird, for some reason the Id of the ViewModel is being rendered as null inside the view. I debugged the application and checked that the view model is actually being mapped correctly (using AutoMapper) and everything is fine. But when I do @Model.Id, it is rendering as zero, and when I alert the value using jQuery I get "null". So what's going on? <div id="commentBox"> @using (Html.BeginForm("Comment", "Item", new { itemId = Model.Id } )) { <span class="greenText">answer</span

Valums qq.FileUploader doesn't work when it's initialized after loading button by ajax

社会主义新天地 提交于 2020-01-25 08:36:25
问题 I use Valums qq.FileUploader(ex-AjaxUpload) plugin for uploading in my Asp.net mvc 3 application... I have some button in my page add-newimage , and by clicking in it I get modal window, and I load data into that window by loading Partial View. And in that partial view I have button upload-image , in which I want to initilaize my qq.FileUploader, but it doesn't work anywhere... Here is code $("#add-newimage").click(function () { $("#add-image").load('/Design/AddImage/', function () { $("#add

How to use jQuery change event on dropdownlist to populate another dropdownlist using an ActionResult in the Controller

大憨熊 提交于 2020-01-25 07:15:07
问题 I am trying to use the change event of a dropdown to call an ActionResult in my controller in order to populate another dropdown. Here is the jQuery that I've tried: $(function () { $('#CertificationId').change(function () { var data = { certificationId: $('#CertificationId').val() }; var certificationId = $('#CertificationId').val(); // $.post('@Url.Action("AjaxGetCourseOptions", "WorkerCertifications")', {certificationId : certificationId}, $(this).parents('form:first').serialize(),

MVC3 - Authenticate with SQL Server Accounts

▼魔方 西西 提交于 2020-01-25 04:22:05
问题 I couldn't find anything useful to this problem and I never used authentication in a web application before. So anything with / without cookies is new for me. We've got an existing (non-web-)program using SQL Server accounts for authentication. Now, I want to do the same with my MVC3 project. Every user has the same rights inside the database. The (non-web-)program handles the rights itself. After logging in successful (with an SQL account), the login name is mapped to an entity in the

Pass model to Controller from jquery ajax

馋奶兔 提交于 2020-01-25 03:37:04
问题 How can I pass model to jquery ajax my code id '@Model' is the model on the view.i need to pass this model to controller which accept argument of type login model. $('#reject1').click( function() { var model=@Model; $.ajax({ cache:true, type: "POST", url: "@(Url.Action("Login", "Customer"))", data:'model='+model, success: function() { //Some logic }, complete : function() {} }); return false; }); Above code doesn't work 回答1: For corrected post data you should serialize model data: $('#FormId'

Load a View from outside the Views folder

别说谁变了你拦得住时间么 提交于 2020-01-25 02:21:53
问题 I'm working on a widgetmanager for asp.net mvc and to get the main part to work, I need to load in a view from outside the default views folder. I got the following folder structure: ... - Views - Widgets |- Views I need the views to be loaded from inside ~/Widgets/Views I'm not sure if I should be writing a Viewengine from scratch or do something else so please feel free to answer :) p.S. The widgetmanager is called S3WidgetManager and can be found on GitHub 回答1: You could write a custom

Form Cookie Expiring too soon on production server

不羁岁月 提交于 2020-01-24 21:07:11
问题 i have following settings in web.config <authentication mode="Forms"> <forms loginUrl="~/Account/login" slidingExpiration="true" timeout="2880" protection="All" /> </authentication> but the cookie expires in less than five minutes of inactivity. Any clue on what is happening? 回答1: I recognize this behavior from a web host where I run one of my sites. It all started when moving to new servers, prepared for dotNET 4. The web.config is completely ignored and, as you mention, five minutes seems