MVC :: How To Return Unencoded HTML To A Razor View


HtmlHelperExtensions in MVC2 return a HTML string, unencoded. In MVC3 this string is encoded! How can I return unencoded HTML to a Razor view in MVC3?

View Answers
Very similar questions



Send MVC Actionresult To Printer stackoverflow.com

I have a controller with an action: SomeController/ActionToBePrinted.ActionToBePrinted() returns an html view.This action is called from a normal mvc razor view when pressing a button - how would I go about sending the content of the view to a printer when the button is pressed?

MVC :: Razor View Engine With ". NET Empty Web Application"? forums.asp.net

point me in the direction of getting the Razor View Engine working correctly with an empty "non MVC" web application. I can correctly set it up with a MVC app or with a Web Site (Razor), but if I try and get it running with and empty app, I run into the following two problems: 1) I can't add new razor files to the application (*.cshtml files) 2) Once deployed to AppHarbor, the .cshtml files aren't found unless they have the extension specified (i.e. /Default won't work, but /Default.cshtml does)

MVC :: Unit Test Razor View In 3? forums.asp.net

Is it possible to write unit tests against razor view in MVC 3? If yes, can anyone point me to code sample to unit test a razor view in MVC 3?

MVC :: Separate Login Page From Master Page? forums.asp.net

i am using mvc3 and razor view engine, when i request login page, the page views in master page. i do not want to this. because i am making an admin page so the page must be free from master page. i will design a new page for login that included username and password inputs. aspx view engine includes Page Inherits="System.Web.Mvc.ViewPage but razor view does not include

MVC :: How To Replicate In The Grid.Column Is Similar forums.asp.net

In a classic Tabular MVC View I have put a column that shows or hide some Html.ActionLink() tags for every row, depending on the model. I was trying to do the same with the razor WebGrid, but not being able to do that. The code snippet I want to replicate in the grid.Column is similar to this @if (item.CanDelete) { Html.ActionLink("Delete","Delete", new {id=item.id} } else { Html.ActionLink("Edit","Edit",new {id=item.id}) }

MVC :: MVC 3 RC 2 Version / Getting Error forums.asp.net

I am updating a MVC 3 Beta working project to MVC 3 RC2. I have the following Assemblies: System.Web.Mvc (3.0.11209.0) System.Web.Helpers (1.0.11209.379) System.Web.Razor (1.0.11209.379) System.Web.WebPages (1.0.11209.379) System.Web.WebPages.Razor (1.0.11209.379) Microsoft.Web.Infrastructure (1.0.11209.379) Microsoft.Web.Mvc (3.0.10714.0) I got the Microsoft.Web.Mvc from the MvcContrib project which I am already using: MVCContrib ( When I run my MVC 3 RC2 project I get the following error: ---------------------------- StructureMap configuration failures:

MVC :: How To Use Local Resources With Razor forums.asp.net

It seems that using Local resources is much more complicated when using Razor. I recently converted an MVC 2 app I was working on to MVC 3. The conversion went well but accessing LocalResources doesn't work and I can't get it to work. In MVC 2 I created an App_LocalResources folder in the /Views/Home folder and created an Index.aspx.resx resource file. In the Index View I could access the local resources with <%: GetLocalResourceObject("FirstName") %> Simple, out-of-the-box functionality, as it should be. Razor doesn't understand this. It seems that in Razor you have to use @HttpContext.GetLocalResourceObject(<virtual-path>, <resource-name-key>). I've tried everything for virtual-path but nothing seems to work ("~/", "~/Views/Home/App_LocalResources", etc.). I tried to directly access the resource file by providing the complete namespace, like you do with global resources (which works fine in Razor), but then it errors stating that the culture is required. Intellisense allows you to build the reference to the resource property but Razor doesn't understand it. Of course an alternative could be to simply use the ASPX rendering engine in MVC 3, but I want to use Razor. Does anyone know an out-of-the-box method (not some exotic work-around) for accessing the LocalResources in an MVC 3 app using Razor?

MVC :: Bind Static Html Controls? forums.asp.net

How do you bind static html controls on MVC? This MVC textbox helper can bind values on return <% =Html.TextBox("firstname", Html.Encode(item.FirstName), New With {.class = "txtClass"})%> but not on a static textbox. <input id="firstname" name="firstname" type="text" value="Joe" /> Public Class Personal Private _FirstName As String Public Property FirstName() As String Get Return _FirstName End Get Set(ByVal value As String) _FirstName = value End Set End Property End Class <AcceptVerbs(HttpVerbs.Post)> _ Public Function Index(ByVal member As Personal) As ActionResult Return View() End Function

MVC :: No Unobtrusive Validation If Html.BeginForm In Layout Template? forums.asp.net

I have a project using MVC 3 RTM and the Razor View engine.I am using a _Layout view in which the Html.BeginForm() is located. [Code].... The Browse.cshtml contains (simplified) [Code]....

HtmlAttributes On ASP.NET MVC 3 With Razor View? stackoverflow.com

how do I add this htmlAttribute on MVC 3 Razor view? New With {.watermark = "sometext", .title = "sometext"} I tried the C# way but it's not working (@watermark) but it's not working. UPDATE here is the current usage I am trying but it's not working. @Html.EditorFor(Function(model) model.FirstName, New With {.maxlength = "50"}) This isn't working either @Html.EditorFor(Function(model) model.FirstName, New Object() {"maxlength=50"})


Razor Templates Helpers To Work? www.sitepoint.com

With the release of mvc 3 rc, I've started playing around with the Razor engine. Has anybody gotten razor templated helpers to work? If so, how? I have a single helper in View/Helpers folder and a single layout page. If I move the code to the view page, it works. The error is ' not in context' for the method name. How and where do I correct this?

Partial Views In Java Spring MVC? stackoverflow.com

I am wondering if Java Spring MVC has some sort of implementation that relates to returning partial views like ASP.NET MVC? Basically I want to return HTML, that is bound to an object and return it to a javascript callback to append to the dom, stead of building the html with Jquery (which is tedious). If not I may go with Jquery templates.

MVC :: Code Not Working In Razor Output forums.asp.net

This same code working fine with MVC 2 but not working in MVC 3 razor. Once page is loaded not loading menu from HTMLHelper called within Razor like below. Hardcoded menu for testing which is not outputting on the page. [Code].... Below is Razor cshtml code. [Code]....

MVC :: Razor View Engine - How To Register The Partial Views In 3 Beta forums.asp.net

On my projects I am using Razor View engine and I need to define custom Partial folders: [Code].... I had this because there was a problem in MVC 3 Preview. Was it corrected? How should I register the Partial Views in MVC 3 Beta?

Asp.net Mvc - Razor View Engine Quirks ? stackoverflow.com

I just downloaded the MVC 3.0 RC and I'm excited to start using it, especially the Razor view engine. However, due to a few stick in the mud type people here, we are stuck using VB.NET instead of C#.When I started trying it out, I noticed some quirks. If you are creating a Razor view using CSHTML, you can write code like this: @foreach(string genreName in Model.Genres) {<li>@genreName</li> } Razor will automatically detect that the <li> text is an HTML tag and will switch out of "code mode". With a VB.NET VBHTML file, this doesn't seem to be working. It's making me put the @: keyword in front of each line like this: @For Each genreName As String In Model.Genres @:<li>@genreName</li> Next If I don't have it there, I get a runtime error. Also, the <text></text> tags don't seem to work.

Razor Support Of Generic Extension Methods? stackoverflow.com

With regards to the Razor view engine, say I want to render Html.TextBoxFor<SomeModel>(i => i.Name), it doesn't seem that the inline syntax works as in: @Html.TextBoxFor<SomeModel>(i => i.Name) This doesn't seem to work because it interprets the generic as an HTML tag. I could use a code-block approach, but then what's the best approach to output the content? The HTML string returned from this method, do I response.write it, or is there a syntax for it, or what's the approach?

MVC :: Migrate 2 Project To 3 - Razor View forums.asp.net

I have an application which has been built in MVC 2.0. I need to upgrade it to MVC 3.0 and that too by using Razor CSHTML engine. All the information which I got on the net was for MVC 3.0 Webform engine but nothing much for migrating to Razor.

MVC - Share Partials Between Areas stackoverflow.com

is there some way to share a partial razor view between areas? For example a login partial, it is found if i use @Html.Partial("_LoginPartial") but the URLs Html.ActionLink generates are local to the calling area (even though the partial itself is not part of the area). _LoginPartial.cshtml is in /Views/Shared/_LoginPartial.cshtml Calling view is inside /Areas/Somearea/Views Links generated are like: [URL] But should always be: [URL] Partial view source: @if(Request.IsAuthenticated) { <text>Welcome <b>@Context.User.Identity.Name</b>! [ @Html.ActionLink(@Messages.Logout, "Logout", "Account") ]</text> } else { @:[ @Html.ActionLink(@Messages.Login, "Login", "Account") ] }

Make Code Indentation Behave Correctly In Vbhtml Razor Files? stackoverflow.com

This is driving me round the bend. I'm a long time VB.NET forms developer, quite new to ASP.NET and completely new to MVC. I'm creating vbhtml pages that use the VB.NET razor syntax, and I seem to be constantly fighting against the UI which is trying to indent my code incorrectly. Take the following example, based on the template page for a new Razor view: @Code Layout = Nothing End Code [code].....

Model View Control Versu Model View Presenter forums.asp.net

I have been reading about different model for development model view control mvc model view presenter MVP Model view view model MVVM i belive MVC has two big Advantage over webform 1) TDD 2) More control on HTML MVP is bit variation in mvc model. rapid development as well as 1) TDD 2) More control on HTML (correct me if i m wrong) see the below link [URL]

MVC :: Route Returns A 404 Error Sometimes? forums.asp.net

when the server reboots, one route sometimes returns a 404 until the site is manually restarted. why is that? using mvc 3 rc1 and razor views.

WebMatrix :: MVC 3 Preview - Idea For Razor Intellisense And Colorization? forums.asp.net

When you do introduce intellisense and colorization to the razor editor, what about allowing the developer to choose the schema that it verifies against? If it could by default use a flavour of HTML, but optionally allow the dev to reference an arbitary XSD file (as supportted by the XML text editor). It could result in a very flexible experience that supports using ASP.Net MVC as a web service returning XML.

MVC :: Razor - Create Instance Of View? forums.asp.net

In my controller method, I'm trying to create an instance of a View (cshtml file) before I wrap it around an ActionResult and return it.Since there is no "class" for Razor Views to speak off, how does one go about creating an instance of a Razor View?

MVC :: Implementing And Showing Time Difference? forums.asp.net

I wanted to display the relative time difference in my razor view page. In my model, which I am passing to the view, in which I have a dateTime datatype variable. Now, I want to implement a funtion like this [Code].... I am unsure how should I define my funtion and call it inside my razor view. In the funtion, I will only pass the Datetime variable. It should only return the time in string format.

MVC 3 Razor Syntax - Partial View Menu.cshtml With Full Markup stackoverflow.com

This question appear when I worked with partial view (MVC3/Razor), but I am sure - it's clear Razor Syntax question, not related direct to partial view. So - I have partial view Menu.cshtml with full markup as: @model IEnumerable<SportsStore.WebUI.Models.NavLink> @foreach(var link in Model) { @Html.RouteLink(link.Text, link.RouteValues); } No problem - "parent" view call it @{Html.RenderAction("Menu", "Nav");} and all work as magic. But, if I will edit the Menu.cshtml as: @model IEnumerable<SportsStore.WebUI.Models.NavLink> @foreach(var link in Model) { Html.RouteLink(link.Text, link.RouteValues); } (see - NO '@' before Html.RouteLink!) all just broke: now @{Html.RenderAction("Menu", "Nav");} output is totally empty, no one HTML tag. Want to know - what is the difference between two piece of code? I assume @ before foreach also automatically "drop into" and apply to Html.RouteLink as well? So - am I wrong?

MVC :: How To Set Size For Textbox When Using Html Hepler In View forums.asp.net

In mvc view, using following code to create html textbox: <%= Html.TextBox("Name")%> But how to set the size for this textbox?

MVC :: How To Manually Execute ActionResult Of Child-action forums.asp.net

Normally, we render a child-action by this code: [Code].... But child-action can not return a redirect-action-result, because this code is excuted when server is rendering HTML to client. Now, I want to invoke an action by code in Controller, it returns an ActionResult. Then, if it's a redirect-result, I returns it. Otherwise, in Razor code, I renders this ActionResult. For example: In controller: [Code].... In view: [Code]....

MVC :: Display Html.Actionlink Through Controller? forums.asp.net

I am trying to display Html.Actionlink through controller(MVC). Here is the example what am trying to do... public string test(){ string testString = "<%: html.ActionLink('click', 'test', new AjaxOptions() { UpdateTargetId = 'test' }) %>"; return testString; } i want to display testString in view. but am not getting the actionlink in view..i can display anchors which is given below:- public string test(){ string testString = "<a href ="test"> click here</a>"; return testString; }

MVC :: Handle Strongly Typed Views If Have Multiple Objects/models? forums.asp.net

<p>Hi</p> <p>I'm a newbie in MVC but a veteran web forms developer. I really like the idea of strongly typed views but what if I have multiple objects to pass to my razor view. Would I then NOT use strongly typed views and just use the ViewBag?</p>

MVC :: Razor View Engine And Add Namespace In Web.Config forums.asp.net

I am working on a MVC project with Razor view engine and I have the following: [Code].... This only works if I have on the same view the following: [Code].... So if "SquishIt.Framework" namespace is added on Web.Config why do I need to have the @using on the view?

Html.ActionLink() Gives An Empty Link When Use It Inside Html.RenderAction()? stackoverflow.com

I have a Microsoft MVC project with an action "Foo" whose view ("Foo.aspx") contains the lines: <%= Html.ActionLink("mylinktext1", "bar") %> <%= Html.ActionLink<MyController>(x => x.Bar(), "mylinktext2") %> When I hit this from a web browser or load it from an AJAX call, it properly returns: <a href="/bar">mylinktext1</a> <a href="/Bar">mylinktext2</a> But when I call the action from another view like this: <% Html.RenderAction<MyController>(x => x.Foo()); %> Then the links are rendered without targets. <a href="">mylinktext1</a> <a href="">mylinktext2</a> Why would this be happening, and how do I work around it?

Is There An Equivalent To Ruby On Rails' Respond_to Format.xml, Etc In MVC stackoverflow.com

In Ruby on Rails you can write a simple controller action such as: def index @movies = Movies.find(:all) respond_to do |format| format.html #index.html.erb format.xml { render :xml => @movies } format.json { render :json => @movies } end end For those unfamiliar with RoR, def index in this case would be the equivalent of public ActionResult Index() within an ASP.Net MVC Controller and would allow the following calls: [URL] returns as an html page from the view index.html.erb (think index.aspx)[URL] returns the same data in xml format (@movies is the object containing the data all of the views use)[URL] returns a JSON string, useful when making javascript calls needing the same data/logic An equivalent flow in ASP.Net MVC would (if possible) likely look something like this (if it could be less verbose, even better): [code]....

MVC :: Unit Testing Razor View? forums.asp.net

How can I render a razor view in a Unit Test?When I change for instance a html helper method, I sometimes forget to update all the views which uses that html method. So the view I forgot generates a YSOD.I would like to create unit tests that renders a view and fails if I forgot to make the neccecary updates.

MVC :: How To Upgrade MVC 1 Project To MVC 3 Razor [trouble] forums.asp.net

I have a project who build in MVC 1 and i make a new fresh project to migrate them in MVC 3. so it's work fine. but whenever it's come to done or complete we hear that not make changes in Admin panel.so i copy paste the model [logic module] from MVC 1 to MVC3 and now many of code was not worked. they used dll to use logic. when i try to use them in my project who is new version that's not worked.now i thing to migrate the MVC 1 project to MVC 3 and the taks and changes i do last days i integrated in old one.well tell me the way i can use to migrate the MVC 1 project to MVC 3 razor without making new project. means changes in old and make them work fine in razor.

MVC :: Javascript / Jquery Value Lost On Submission Using Ajax forums.asp.net

Why do I lost the invoked content from a javacript or jquery after I submit it from an Ajax submission using MVC? I simply don't want to lose those values after submission, but it did. Index.aspx <asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server"> <% Html.RenderPartial("myForm")%> </asp:Content> HomeController.vb <HandleError()> _ Public Class HomeController Inherits System.Web.Mvc.Controller Function Index() As ActionResult Return View() End Function <AcceptVerbs(HttpVerbs.Post)> _ Public Function Index(ByVal formValues As FormCollection) Return PartialView("myForm") End Function End Class myForm.ascx <%@ Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl" %> <script src="<%= Url.Content("~/scripts/jquery-1.3.2.min.js") %>" type="text/javascript"></script> <script src="<%= Url.Content("~/scripts/MicrosoftAjax.js") %>" type="text/javascript"></script> <script src="<%= Url.Content("~/scripts/MicrosoftMvcAjax.js") %>" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $("#Keep_this_value_no_matter_what").append("This javascript or jquery value is lost after ajax submission...:-("); }); </script> <% Ajax.BeginForm(New AjaxOptions With {.UpdateTargetId = "ajaxDiv"})%> <div id="ajaxDiv"> <span id="Keep_this_value_no_matter_what"></span> <p> <label> Name </label><br /> <%=Html.TextBox("FieldName", "", New With {.size = "40", .tabindex = "1"})%><br /><br /> <label> Message </label><br /> <%=Html.TextArea("FieldMessage", "", New With {.class = "className", .rows = "10", .cols = "50", .tabindex = "2"})%> <p> <%=Html.TextBox("submit", "Submit", New With {.type = "submit", .tabindex = "3"})%> </p> </div> <% Html.EndForm()%>

MVC :: How To Reinstall 3 Tools For Visual Studio forums.asp.net

I removed mvc3 tools for visual studio, and now it seems no matter how much reinstalling, or un-installing i do i cant get razor project templates or intellisence for razor.I have even removed the visual studio folder and visual studio hives in the registry but still the same. I seem to remember a simular problem with mvc2 tools, that the installer doers not reconize it as un-installed and therefore does not re-install it.how can i re-install mvc tools so VS reconises razor, or remove all trace of visual studio and mvc3 so that i can start again?

.net - Date Formatting String In Vb Mvc? stackoverflow.com

How do I format my vb.net mvc date to a shortdate in my view <td> <%: Html.DisplayFor(Function(modelItem) currentItem.DateCreated)%> </td>

Upgrading A Regular .net Project To .net Mvc 3 (RC2) With Razor Syntax? forums.asp.net

I'm upgrading a regular asp.net project to asp.net mvc 3 (RC2) with Razor syntax. I got stuck now trying to figure out some way to create nested master pages. My main "layout" page contains the default header & footer. I used [Code].... When I now try to make a view page use the AuthLayout as a "layout" page: [Code]... Then I receive this error: The "RenderBody" method has not been called for layout page "~/Views/Shared/_AuthLayout.cshtml".

Asp.net Mvc 3 - PayPal Ipn With MVC 3 Status 200 But Not Logging Transaction At All? stackoverflow.com

Using VB MVC 3 with Razor ... can I create the PayPal ipn in any controller? say I put it in its own controller say IPN. Would the URL not then be [URL] ? and if that is correct. Do I need to create a blank view page named Ipn or what ever the Ipn action name is?? In this view would It need to contain any razor syntax? I have been back and fourth over every single post I could find about IPN but there is nothing for MVC 3 vb.net.. This has been edited... I have got the IPN handler reutrning status 200. And when I run it through the tester I get success... However actual test transactions are not being entered in the database...The Ipn Controller function is this: End Function <AcceptVerbs(HttpVerbs.Post)> Function IPN_Handler(ByVal sender As Object, ByVal e As System.EventArgs) Dim strFormValues As String = Request.Form.ToString() [code]....