asp.net-mvc-5

MVC 5 ViewBag security

六月ゝ 毕业季﹏ 提交于 2021-01-27 14:29:05
问题 I am coding an MVC internet application, and I have a question in regards to using the ViewBag. In many of my controllers, I have SelectList objects, where the user can select an object. The object that is selected is a foreign key value for my model. My question is this: Should I use ViewBag for this? How secure is the ViewBag? Should I use values in my ViewModel instead of the ViewBag? Thanks in advance. 回答1: Use your view model. When the ViewBag was implemented (MVC 3) dynamic typing was

MVC 5 - Adding Client Validation to refuse the default value?

喜夏-厌秋 提交于 2021-01-27 14:24:53
问题 I'm using a DropDownListFor and provide a default selection of -- Select Make -- which has an empty value. I want to provide the user with a hint of what to do (thus the 'Select Make') but don't want to allow them to actually submit that value. Currently the website allows this to go through. I thought that adding a minimum length of 2 would prevent it but no luck. I'm fairly new to .NET MVC so let me know if I'm doing this in the completely wrong way. The actual POST request body is: Make=

ASP MVC 5 - 403 customError not working

旧时模样 提交于 2021-01-27 13:18:22
问题 I am trying to create custom error pages for my application and it's working for the most part, but not for 403 errors. My Web.config: <customErrors mode="On" defaultRedirect="~/Error"> <error statusCode="404" redirect="~/Error/NotFound" /> <error statusCode="500" redirect="~Error/InternalServer" /> <error statusCode="403" redirect="~Error/Forbidden" /> </customErrors> I have an ErrorController that is delegating these requests. When the 404 hits, it displays the custom error page, but 403

jQuery Validate with Summernote Editor error: Cannot read property 'replace' of undefined

老子叫甜甜 提交于 2021-01-21 06:19:59
问题 I am using MVC5 to build a form with summernote editor. Razor code: <div class="form-group"> @Html.LabelFor(model => model.Content, htmlAttributes: new { @class = "control-label" }) @Html.EditorFor(model => model.Content, new { htmlAttributes = new { @class = "form-control post-content"} }) @Html.ValidationMessageFor(model => model.Content, "", new { @class = "text-danger" }) </div> JS: $('#blog-form .post-content').summernote({ height: 400, minHeight: 300, codemirror: { theme: 'default' } })

jQuery Validate with Summernote Editor error: Cannot read property 'replace' of undefined

和自甴很熟 提交于 2021-01-21 06:19:19
问题 I am using MVC5 to build a form with summernote editor. Razor code: <div class="form-group"> @Html.LabelFor(model => model.Content, htmlAttributes: new { @class = "control-label" }) @Html.EditorFor(model => model.Content, new { htmlAttributes = new { @class = "form-control post-content"} }) @Html.ValidationMessageFor(model => model.Content, "", new { @class = "text-danger" }) </div> JS: $('#blog-form .post-content').summernote({ height: 400, minHeight: 300, codemirror: { theme: 'default' } })

Posting Back DropDownList from Strongly Typed View

纵饮孤独 提交于 2021-01-07 03:52:42
问题 This is related to an earlier question on binding a dropdownlist from a database. The dropdownlist is being bound and populated but is throwing an "Object reference not set to an instance of an object" error in the browser when submitting the form. When debugging, I added a quick watch on the m => m.SelectedDepartment parameter of the Html.DropDownListFor(...) helper method and got: "Cannot convert lambda expression to type 'object' because it is not a delegate type". View: @model BudgetDemo

Can't access views from different project using Razor View Engine

坚强是说给别人听的谎言 提交于 2021-01-05 07:11:13
问题 I have a use case where I have many web projects that all use the same management general-purpose web pages, so I started to isolate my views to a separate project where all solutions can reference and use. Because currently, I have to copy-paste the view files across solutions whenever I have a new change. Based on this answer, I added a new custom view engine, and then added the path to the location where my views live (in a separate project beside my main project). public class

Can't access views from different project using Razor View Engine

折月煮酒 提交于 2021-01-05 07:11:12
问题 I have a use case where I have many web projects that all use the same management general-purpose web pages, so I started to isolate my views to a separate project where all solutions can reference and use. Because currently, I have to copy-paste the view files across solutions whenever I have a new change. Based on this answer, I added a new custom view engine, and then added the path to the location where my views live (in a separate project beside my main project). public class

Can't access views from different project using Razor View Engine

两盒软妹~` 提交于 2021-01-05 07:08:33
问题 I have a use case where I have many web projects that all use the same management general-purpose web pages, so I started to isolate my views to a separate project where all solutions can reference and use. Because currently, I have to copy-paste the view files across solutions whenever I have a new change. Based on this answer, I added a new custom view engine, and then added the path to the location where my views live (in a separate project beside my main project). public class

MVC 5 prevent page refresh on form submit

筅森魡賤 提交于 2021-01-04 07:43:45
问题 yBrowser: IE9 Technologies: MVC5 I am mainly using Angular for everything on my page. (Single Page App). But because I am working with IE9, I can't use FileAPI.. So, I decided to go with MVC's Form Actions to get HttpPostedFileBase in my controller methods to handle fileupload. Html Code: (Is present in a modal) @using (Html.BeginForm("UploadTempFileToServer", "Attachment", FormMethod.Post, new { enctype = "multipart/form-data", id = "attachmentForm" })) { <div> <span id="addFiles" class="btn