razor

Is it possible to display raw Html from database in ASP.NET MVC 3?

你说的曾经没有我的故事 提交于 2019-12-27 23:37:51
问题 I have a table in my db where one of the properties is an Html page (without the html, head and body tags), and I intend to put it in the middle of one of my views - say, I call a cotroller method that takes an argument, and return a view passing this html big string as the model. I searched for it (not much, I admit), and found the following method: <%= System.Web.HttpUtility.HtmlDecode(yourEncodedHtmlFromYouDatabase) %> That was found here in stackoverflow. When I tried a similar razor

ASP.Net MVC 4 Form with 2 submit buttons/actions

大城市里の小女人 提交于 2019-12-27 19:11:14
问题 I have a form in ASP.Net and razor. I need to have two ways of submitting said form: one that goes through the Edit action, and another that goes through the Validate action. How should I go about doing this? I don't mind using JavaScript for this. EDIT: Using the custom attribute I get this error. The current request for action 'Resultados' on controller type 'InspecoesController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult Validar(System.Collections

ASP.Net MVC 4 Form with 2 submit buttons/actions

坚强是说给别人听的谎言 提交于 2019-12-27 19:10:52
问题 I have a form in ASP.Net and razor. I need to have two ways of submitting said form: one that goes through the Edit action, and another that goes through the Validate action. How should I go about doing this? I don't mind using JavaScript for this. EDIT: Using the custom attribute I get this error. The current request for action 'Resultados' on controller type 'InspecoesController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult Validar(System.Collections

Razor Syntax and Javascript

不打扰是莪最后的温柔 提交于 2019-12-27 17:12:14
问题 As a test I'm converting a proof-of-concept app we've written from Web Forms to Razor, simply so we can evaluate it. I've run into one problem so far that's making my head hurt..generating client-side Javascript... Web-Forms <script type="text/javascript"> var jqGridIdList = "<%: Url.Action ("getidlist", "office", new { area = "reports" }) %>"; var availableIds = []; <% for (var i = 0; i < Model.Data.Count (); i++) { %> availableIds.push({ value : "<%: Model.Data.ElementAt (i).Text %>", label

Razor Syntax and Javascript

ⅰ亾dé卋堺 提交于 2019-12-27 17:09:52
问题 As a test I'm converting a proof-of-concept app we've written from Web Forms to Razor, simply so we can evaluate it. I've run into one problem so far that's making my head hurt..generating client-side Javascript... Web-Forms <script type="text/javascript"> var jqGridIdList = "<%: Url.Action ("getidlist", "office", new { area = "reports" }) %>"; var availableIds = []; <% for (var i = 0; i < Model.Data.Count (); i++) { %> availableIds.push({ value : "<%: Model.Data.ElementAt (i).Text %>", label

Possible to access MVC ViewBag object from Javascript file?

旧街凉风 提交于 2019-12-27 17:04:19
问题 Is it possible to do the following from a javascript file in an MVC application? $(function(){ alert(@ViewBag.someValue); } Currently it throws the error: reference to undefined XML name @ViewBag 回答1: I don't believe there's currently any way to do this. The Razor engine does not parse Javascript files, only Razor views. However, you can accomplish what you want by setting the variables inside your Razor view: <script> var someStringValue = '@(ViewBag.someStringValue)'; var someNumericValue =

Possible to access MVC ViewBag object from Javascript file?

前提是你 提交于 2019-12-27 17:03:17
问题 Is it possible to do the following from a javascript file in an MVC application? $(function(){ alert(@ViewBag.someValue); } Currently it throws the error: reference to undefined XML name @ViewBag 回答1: I don't believe there's currently any way to do this. The Razor engine does not parse Javascript files, only Razor views. However, you can accomplish what you want by setting the variables inside your Razor view: <script> var someStringValue = '@(ViewBag.someStringValue)'; var someNumericValue =

Serving favicon.ico in ASP.NET MVC

百般思念 提交于 2019-12-27 11:50:10
问题 What is the final/best recommendation for how to serve favicon.ico in ASP.NET MVC? I am currently doing the following: Adding an entry to the very beginning of my RegisterRoutes method: routes.IgnoreRoute("favicon.ico"); Placing favicon.ico in the root of my application (which is also going to be the root of my domain). I have two questions: Is there no way to put the favicon.ico somewhere other than the root of my application. It's pretty icky being right there at the same level as Content

Convert C# model to plain json-string

一笑奈何 提交于 2019-12-26 16:31:22
问题 Is there any simple way to convert an C# -object into a plain string that is escaped and can be used by javascript? I try to pass the string into a jQuery-function which will replace some parts of this string with real values to pass them as request-object via $.ajax . Whatever I tried (found in the internet) doesn't work. Currently I have: var jsVariable = "@Html.Raw(Json.Encode(new MyClass()))" but this throws an Uncaught SyntaxError: Unexpected identifier as of the " are not escaped

how to pass viewbag data from view to another component template that I call in this view

青春壹個敷衍的年華 提交于 2019-12-25 19:36:19
问题 I have a ViewBag data from the controller that I get in the View . However, my view is made of multiple components and a component (Which is a html template and relevant JavaScript ), has a placeholder for this data where I need to display this data. How would I pass this @ViewBag.Data to the placeholder in another view (Template here). ? Or, would it be easy to consider passing the data from Controller to another view ? Please help me with a sample snippet 回答1: If I understood correctly you