asp.net-mvc-3

Context lifetime management in repository and unit of work pattern

人盡茶涼 提交于 2020-02-08 07:24:31
问题 I have a repositories implemented with unitOfWork pattern and share a context. i have a service layer on top of these repositories. which has multiple services. When ever i instantiate a service class - unitOfWork instance is created. But many times these services methods call each other and sometimes operate on common session objects. Which causes a problem of the same entity being tracked by multiple contexts or more specifically - An entity object cannot be referenced by multiple instances

MapRouting default querystring values?

扶醉桌前 提交于 2020-02-08 07:19:05
问题 I have this route map (notice that topicName is ignored): routes.MapRoute( "Topics", // Route name "Topic/{topicName}/{action}", new { controller = "Topic", action = "AddQuestion" }); And I want it to defaultly map to this Url: http://localhost:51421/Topic/SomeName/AddQuestion?topicId=1 (or if that's not possible,to this url: http://localhost:51421/Topic/SomeName/AddQuestion/topicId/1) (which should invoke this action: public ActionResult AddQuestion(int topicId) { return View(); } ) But

User roles and authorization

对着背影说爱祢 提交于 2020-02-07 12:25:48
问题 So I want to create a login page where when you enter your login credentials as a admin you get acces. If you are not a admin you get redirected back to the login page. In my database I have a field of boolean type: isAdmin <--datatype(byte") So how can you the best way do this?! I would like to do this in the repository pattern way as it gets easier to unit test it then. I have googled this a lot and starting to get a bit confused on the matter. How many classes, models etc should I have?! I

User roles and authorization

陌路散爱 提交于 2020-02-07 12:25:31
问题 So I want to create a login page where when you enter your login credentials as a admin you get acces. If you are not a admin you get redirected back to the login page. In my database I have a field of boolean type: isAdmin <--datatype(byte") So how can you the best way do this?! I would like to do this in the repository pattern way as it gets easier to unit test it then. I have googled this a lot and starting to get a bit confused on the matter. How many classes, models etc should I have?! I

How to pass class via RedirectToAction

筅森魡賤 提交于 2020-02-04 15:50:13
问题 I have the following code: public ActionResult Index() { AdminPreRegUploadModel model = new AdminPreRegUploadModel() { SuccessCount = successAddedCount, FailureCount = failedAddedCount, AddedFailure = addedFailure, AddedSuccess = addedSuccess }; return RedirectToAction("PreRegExceUpload", new { model = model }); } public ActionResult PreRegExceUpload(AdminPreRegUploadModel model) { return View(model); } but model is null when I breakpoint on PreRegExcelUpload. Why? 回答1: Instead of using the

How can I access unvalidated items in the Request.Form collection in MVC 3

依然范特西╮ 提交于 2020-02-03 07:50:06
问题 I am using ASP.NET MVC 3 with .NET 4.0. I have a model on which one of the properties requires that HTML content be allowed. I have placed the AllowHtml attribute on my model property which allows HTML on that property. That works by itself. I am also using the Uploadify flash uploader on other parts of my website. Due to problems with flash and sessions, I'm using some code similar to the code in a swfupload example to allow my file upload access to session data. Basically I'm accessing the

SmtpAppender log4net using gmail smtp

谁都会走 提交于 2020-02-02 03:44:20
问题 I configured log4net with a smtpAppender (gmail). The weird issue is that the smtpAppender is not working when I deploy the application on IIS 7.5. I tried to test the connection with the gmail smtp using telnet command. So I can check if anything is blocked but the test worked fine. My log config: <log4net> <appender name="RollingFile" type="log4net.Appender.RollingFileAppender"> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> <file value="C:\logs\MyLog.log"/> <appendToFile

Why is MVC3 not scaffolding my foreign key columns

泄露秘密 提交于 2020-02-01 08:17:21
问题 I'm trying to use MVC 3 with EF 4.1 using code first and am following Scott Guthries tutorial http://weblogs.asp.net/scottgu/archive/2011/05/05/ef-code-first-and-data-scaffolding-with-the-asp-net-mvc-3-tools-update.aspx. The issue I'm having is that when I create the products controller and the related scaffolded views, there is no "category" column being created in any of the views ("edit", "create", "index" etc), which according to the tutorial should be created. I've traced the reason why

MVC3 removed “required” but keeps getting data-val-required attribute

浪尽此生 提交于 2020-02-01 04:17:06
问题 My Model [DataType(DataType.Text)] [Display(Name = "Number of Employee")] public int NumberOfEmployee { get; set; } [DataType(DataType.Date)] [Display(Name = "CEO Birthday")] [DateRange(2)] public DateTime CEO_Birthday { get; set; } [DataType(DataType.Date)] [Display(Name = "Organisation Anniversary")] [DateRange(3)] public DateTime OrgAnniversary { get; set; } My View <tr> <td style="border:0;"> <div class="editor-label"> @Html.LabelFor(m => m.NumberOfEmployee) </div> </td> <td style="border

The model item passed into the dictionary is of type 'Sitecore.Mvc.Presentation.RenderingModel', but this dictionary requires a model item of type 'X'

左心房为你撑大大i 提交于 2020-01-31 16:54:05
问题 I am building a solution with Sitecore 7 and ASP.NET-MVC 3 and trying to use a custom model class as described in this blog post by john west. I have seen several other questions here on SO reporting a similar error with ASP.NET-MVC (without Sitecore), usually related to passing the wrong type of object in controller code, or there being a configuration error with the \Views\web.config file, but neither seem to be the issue here. 回答1: this issue is caused when you create a view rendering