razor

When use IEnumerable in view client side validation is not working?

穿精又带淫゛_ 提交于 2019-12-25 05:10:06
问题 I am passing List from Model to view , so I specified in view like this IEnumerable. In this situation Client side validation is not firing View : @model IEnumerable<ShoppingCart.Models.ShoppingClass> @{ ViewBag.Title = "Display"; } <script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script> @Html.ValidationSummary(true) @using (Html.BeginForm()) { <table>

Possible way to make the page session expired in ASP MVC 3? (“Press Back Button after Logout issue”

点点圈 提交于 2019-12-25 05:06:58
问题 I am currently working on MVC3 website with user authentication. I have this security issue whereby I want to prevent user from relogin back with pressing back button after successfully log out from the page. I had research many solutions, however I do not understand how to apply it into my project. Any possible to do it in MVC3? 回答1: You are not re-logging, you are only viewing page from browser cache. If you try to debug, you will see that no code is executed on back button on browser. If

Failed to load resource: Uncaught TypeError: $(…).select2 is not a function

冷暖自知 提交于 2019-12-25 04:59:13
问题 So my MVC application keeps on throwing an Http internal server error with status code 500 when it renders my view. The error it is throwing is a JQuery "Uncaught TypeError: $(...).select2 is not a function" Uncaught TypeError: $(...).select2 is not a function at HTMLDocument.<anonymous> (AddUser:381) at fire (jquery-1.11.0.js:3100) at Object.fireWith [as resolveWith] (jquery-1.11.0.js:3212) at Function.ready (jquery-1.11.0.js:3424) at HTMLDocument.completed (jquery-1.11.0.js:3454) Using

Using an @section inside a ChildAction to add additional scripts to a page

跟風遠走 提交于 2019-12-25 04:54:20
问题 I've got a MVC View which is made up of a main view and some additional content added via @Html.Action . In the additional content (which is a ChildOnlyAction ) I want to be able to add some JS to the page, but I want to add it to the @RenderSection("Scripts") block which I've defined in the layout. Can my Child Action's View use this: @section Scripts { //Add scripts } So far I haven't been able to get it to work, so if it doesn't what would be an alternative approach? 回答1: Sections do not

Razor DropDownList for each and all elements

夙愿已清 提交于 2019-12-25 04:32:15
问题 Is there a way to create DropDownList with Razor and pass second parameter as Linq result instead of default empty item? The key is that I'm using accumulator function ("Function") so I can not pass null into it (as a answer to that question - Alternative for multiple IF/CASE statements) If DropDownList is not suitable I would really appreciate an alternative. Controller: public ActionResult Index(string searchFullName, string searchExtension, string searchProject) { var extensionList = new

ASP.NET MVC Single View for CRUD operation

…衆ロ難τιáo~ 提交于 2019-12-25 04:28:26
问题 I am working on a ASP.NET MVC project. I have a question about the View in a CRUD operation. In most of the examples I have seen, separate views for each CRUD operation (e.g. Add, Edit, Delete) are used. Now imagine if I have 100 tables in my database, and each of them requires CRUD operations via a View. Is it best to create these separate Views for each table or create a function that would create these Views for me, such as below? public ActionResult CreateSubject() { return View(Model

Inserting model string in span text after button click

ぃ、小莉子 提交于 2019-12-25 04:25:32
问题 Using razor it's easy to show the values of a list in html: <div id="collapse1" style="display:none"> @{ foreach (var i in Model) { <text> <strong>::: @i.City, @i.Country :::</strong> </text> <p style="margin-bottom:0px"></p> foreach (var h in i.Weather) { { <div id="MyDiv2"> <strong><small>@DateTime.Now.AddDays(count).ToString("dd/MM/yy")</small></strong> <p style="margin-bottom:0px"></p> <text><small>Max: @i.MaxTemp.ElementAt(@count)°</small></text> <p style="margin-bottom:0px"></p> <text>

MVC 5: ASPX and Razor View Engine in Visual Studio 2013 Update 4

只愿长相守 提交于 2019-12-25 04:22:46
问题 I am still learning and today I came to a point when I don't understand why something that should work, actually doesn't. My sample project, I wanted to test both aspx and razor engine so i created razor view which works like a charm and now it turned out that there is no way for me to add ASPX View to my project and make it work: (I want to make it work in MVC 5 not MVC 4) There is no option for me to create strongly typed view using ASPX engine at all: When I create it manually: Add .aspx

umbracoNaviHide not working in Where statement

試著忘記壹切 提交于 2019-12-25 04:03:53
问题 Trying to get children of a given document type, with umbracoNavihide not set to false: The following produces correct output. @foreach (var child in root.Children.Where("ContentTypeAlias == \"DocumentTypehere\"")) { if (child.umbracoNaviHide == "False") { continue; } <li>@child.Name</li> } This does not: @foreach (var child in root.Children.Where("umbracoNaviHide == @0 && ContentTypeAlias == \"DocumentTypehere\"","False")) { <li>@child.Name</li> } 回答1: umbracoNaviHide is not supported in

MVC 4 Page not working after altering Html.beginform()

与世无争的帅哥 提交于 2019-12-25 03:54:16
问题 I had been using this line at the top of my edit.cshtml page: @using (Html.BeginForm()) but then I changed it to: @using (Html.BeginForm("Edit", "Home", FormMethod.Post, new { enctype = "multipart/form-data" })) and now when I hit submit on that page I try to run this method: public ActionResult Edit([Bind(Include = "description,tags,files,fileString")] Task task, int keyId, string editFiles) I get this error: The parameters dictionary contains a null entry for parameter 'keyId' of non