I am trying to pass a form element into an MVC3 view by using the Viewbag and simply write the HTML to the page ...
In controller:
ViewBag.myData = "<input type=""hidden"" name=""example"" value=""examplevalue"">";
In view (I know I could use a helper for the form):
<form action="http://exampleurl/examplepage" method="post" id="example-form"> @ViewBag.myData <input type="hidden" name="anotherexample" value="anotherexamplevalue" /> </form>
This renders the myData as text in the HTML i.e.:
<type="hidden" name="example" value="examplevalue">
So my question is how do I get Razor to do the equivalent of older:
<%= myData %>
and not replace the <>
Thanks Paul
can we make use of viewdata or viewbag or tempdata in blazor server application? Thanks for contacting us. Blazor does not postback hence having TempData or ViewData does not apply to Blazor applications. We have directed your feedback to the appropriate engineering team for further evaluation.
ASP.NET MVC - ViewBag. The ViewBag in ASP.NET MVC is used to transfer temporary data (which is not included in the model) from the controller to the view. Internally, it is a dynamic type property of the ControllerBase class which is the base class of the Controller class.
Razor is a markup syntax that lets you embed server-based code into web pages using C# and VB.Net. It is not a programming language. It is a server side markup language. Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine. You can use it anywhere to generate output like HTML.
A view is an HTML template with embedded Razor markup. Razor markup is code that interacts with HTML markup to produce a webpage that's sent to the client. In ASP.NET Core MVC, views are .cshtml files that use the C# programming language in Razor markup.
Use @Html.Raw(ViewBag.Mydata)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With