razor

How to force Razor to make Editorfor to input number type for float variable?

心已入冬 提交于 2019-12-18 01:31:12
问题 Here is my code in MVC 5: @Html.EditorFor(model => model.myfloatvalue, new { @type = "number", @min = "0", @step = "0.01", @value = "0" }) And here is the html code: <input class="text-box single-line" data-val="true" data-val-number="The field Fix Amount must be a number." data-val-required="The Fix Amount field is required." id="myfloatvalue" name="myfloatvalue" type="text" value=""> Not to <input class="text-box single-line" data-val="true" data-val-number="The field Fix Amount must be a

Angular ng-include cshtml page

落花浮王杯 提交于 2019-12-17 23:37:28
问题 Im fighting with angular to make it ng-include a partial cshtml view outside of ng-view. here is my main view: <div class="container"> <div class="header"> <div class="loginView"> <div ng-include="Home/Template/login"></div> </div> </div> </div> <div class="container"> <div ng-view></div> </div> here is my partial Login.cshtml: <form name="login" ng-controller="LoginCtrl" class="form-inline"> <div class="form-group"><input type="text" name="loginName" class="form-control input-sm" placeholder

display line breaks asp.net mvc razor

坚强是说给别人听的谎言 提交于 2019-12-17 23:34:17
问题 I'm using the following to make the text output the line breaks entered in a <textarea> HTML element. MvcHtmlString.Create(Model.Post.Description.Replace(Environment.NewLine, "<br />")) Is there a nicer way to do this? 回答1: Your code is vulnerable to XSS attacks as it doesn't HTML encode the text. I would recommend you the following: var result = string.Join( "<br/>", Model.Post.Description .Split(new[] { Environment.NewLine }, StringSplitOptions.None) .Select(x => HttpUtility.HtmlEncode(x))

MVC 3 Razor @Html.ValidationMessageFor not working in partial loaded via jquery.load()

半世苍凉 提交于 2019-12-17 23:08:37
问题 I have put together a small example here just to replicate the problem. I have a strongly typed partial view _Name.cshtml: @model ValidationInPartial.ViewModels.MyViewModel <h2>@ViewBag.Message</h2> <fieldset> <legend>Name</legend> <div class="editor-label"> @Html.LabelFor(model => model.MyName) </div> <div class="editor-field"> @Html.EditorFor(model => model.MyName) @Html.ValidationMessageFor(model => model.MyName) </div> <a href="#" id="reload">Reload Name</a> <p> <input type="submit" value

Display an image contained in a byte[] with ASP.Net MVC3

时光总嘲笑我的痴心妄想 提交于 2019-12-17 23:05:09
问题 I've a view with a strong type. This strong type has a field consisting of a byte[], this array contains a picture. Is it possible to display this image with something like @Html.Image(Model.myImage) ? Thank you very much 回答1: You can create a controller action method that returns an image as a FileContentResult: public FileContentResult Display(string id) { byte[] byteArray = GetImageFromDB(id); return new FileContentResult(byteArray, "image/jpeg"); } Then you can create an ActionLink to the

How to link HTML5 form action to Controller ActionResult method in ASP.NET MVC 4

蓝咒 提交于 2019-12-17 22:38:30
问题 I have a basic form for which I want to handle buttons inside the form by calling the ActionResult method in the View's associated Controller class. Here is the following HTML5 code for the form: <h2>Welcome</h2> <div> <h3>Login</h3> <form method="post" action= <!-- what goes here --> > Username: <input type="text" name="username" /> <br /> Password: <input type="text" name="password" /> <br /> <input type="submit" value="Login"> <input type="submit" value="Create Account"/> </form> </div> <!

ModelState.AddModelError is not being displayed inside my view

折月煮酒 提交于 2019-12-17 22:37:13
问题 I have the following view,, which create 10 ajax.beginform ,, But the problem that i am facing is that incase an error occurs during the creation of the object then the ModelState.AddModelError will not be shown on the view although i have set the @Html.ValidationSummary(true) The view looks as follow @model Medical.Models.VisitLabResult @for (int item = 0; item < 10; item++) { <tr id = @item> @using (Ajax.BeginForm("CreateAll", "VisitLabResult", new AjaxOptions { HttpMethod = "Post",

Asp.Net Webforms Vs Asp.Net WebSite(Razor) Vs Asp.Net MVC

爷,独闯天下 提交于 2019-12-17 22:32:09
问题 I think Microsoft must have a reason for enhancing ASP.Net with RAZOR syntax. On the Create New Website Project dialog of visual studio, there is another option for creating ASP.Net (Razor). The first time I came across the term Razor was when I read a book on Asp.Net MVC, I didn't know it exists for ASP.Net I know what the Razor syntax is for, introduced in MVC 3. Before asking this question, I decided to create a test project for ASP.Net (Razor) and see how it is different from the normal

How do you include .html or .asp file using razor?

末鹿安然 提交于 2019-12-17 22:26:56
问题 Is it possible to use server side include in Razor view engine to include .html or .asp file? We have an .html file and .asp files that contain website menus that are used for all of our websitse. Currently we use server side include for all of our sites so that we only need to change the mensu in one place. I have the following code in the body of my _Layout.cshtml <body> <!--#include virtual="/serverside/menus/MainMenu.asp" --> <!--#include virtual="/serverside/menus/library_menu.asp" --> <

Displaying database image (bytes[]) in Razor/MVC3?

帅比萌擦擦* 提交于 2019-12-17 22:23:35
问题 I am returning a dataset from my MS SQL 2008R2 database that contains a datatable that I am already getting data from on my Razor view. I added a byte[] field that contains an image thumbnail that I am trying to display on that view. Since the byte array is relatively tiny, I figured I would try displaying the byte array inline. However, after reading there may be some browser-related issues, I abandoned this. Creating a controller method seemed the way to go, (both methods found here),