razor

Rendering HTML content with @Html.Raw in Razor Mail Template

◇◆丶佛笑我妖孽 提交于 2019-12-22 11:03:03
问题 Using Razor page as Mail Template I am trying to display the content of the mail (Html Content) using @Html.Raw(Model.Content) . Anytime I run the code I get this error: html does not exist in current context . I tried this @Html.Raw("<strong>Bold!</strong>") on another razor page to validate RazorEngine is installed and it displayed perfectly well with no error. 回答1: When doing e-mails, I use the RazorEngineService in RazorEngine.Templating, e.g. in my case, it looks like this: using

Dealing with complex models in ASP.NET MVC

柔情痞子 提交于 2019-12-22 10:45:08
问题 I have a model that looks like this: Business - Branch - Phone(*) - Phone Type - Number - Opening hours (*) - Days in week - Working period (*) - From time - To time - Custom field (*) - Name - Value - Address - Address line - City - State - Zip - Yada yada I created Editor Template s for each of the class types above. I want to have a common Business editor template with a submit form that posts the entire structure to a single action and saves it, both for an existing or new entity. Is

Sending email using resulted razor view in MailKit

大城市里の小女人 提交于 2019-12-22 10:20:02
问题 Hope I can explain my request in a simple way: In .Net Core, we can display the .cshtml view, after sending the model data using View(FileName, Model) . Is there a way to send the Model to the .cshtml file, so that instead of displaying the resulting view I get it emailed a attachment using Mailkit 回答1: Thanks to Paris Polyzos and his article. I found the solution, so liked to share it, may some one get a benefit from it, or improve it. Firs: We need to create service to convert the Rasor

HTML Helper in JavaScript?

余生颓废 提交于 2019-12-22 09:59:15
问题 In Razor I can do this: <p @Html.MyCustomDataAttributeFor(person) >@person.Name</p> To render something like this: <p data-custom-person-id="1234567890" >Fred</p> Must I really then do this in (unobtrusive) JavaScript: $('p[data-custom-person-id="1234567890"]').css('background-color','red'); When I'd prefer to do this: $('p[@Html.MyCustomDataAttributeFor(person)]').css('background-color','red'); If only I could, otherwise should the data attribute generated by the HTML helper change, my

Why does Html Helper add prefix to attributes for child item of view model?

一曲冷凌霜 提交于 2019-12-22 09:37:30
问题 I have a view model with a single child entity and various other properties. In my view I want to display a form for the child entity. Using the following code: @Html.HiddenFor(model => model.Item.ItemID) produces the following output: <input id="Item_ItemID" name="Item.ItemID" type="hidden" value="234" /> As you can see, the Html helper has prefixed the id and name attributes, whereas I would have expected the output to be <input id="ItemID" name="ItemID" type="hidden" value="234" />

razor editorfor checkbox event binding

早过忘川 提交于 2019-12-22 09:14:59
问题 I cant bind event to @html.editorfor I've heard it might be connected to presence of "class" attribute but I can see no connection whatsoever. @Html.EditorFor(model => model.SameAsBaseAddress, new { @onclick = "checkboxcheck()" }) function checkboxcheck() { //blah... } When I debug with firebug and add handler manually all works fine. TextBoxFor, RadioButtonFor etc. have no problems with razor event binding. What to do? 回答1: The EditorFor extension doesn't have an argument htmlAttributes like

MVC3 dropdownlistfor

僤鯓⒐⒋嵵緔 提交于 2019-12-22 08:59:12
问题 I would like to make a dropdown list, with the numbers 0-10. So users can rate something. At the moment, I have a label: @Html.LabelFor(model=> model.RATE) How can I modify this code that I will have a dropdown box? And that the value of the dropdown box will be stored in model.RATE? The label is working, but it would be much better to have a dropdown menu. SOLUTION: @Html.DropDownListFor(model => model.RATE, Enumerable.Range(0,11).Select( x => new SelectListItem { Text = x.ToString() }));

.CSHTML pages will not render

天涯浪子 提交于 2019-12-22 08:44:43
问题 I am trying to get my server to run .cshtml files. Using WebMatrix 3 I can view the pages by right clicking and selecting "view in browser", but that views through a localmachine port. If I try to access the pages from the internet, I get a 500 error. Here is what I have done: I made sure that MVC 3 was installed (but I keep reading that MVC is not needed for .cshtml... I made sure anywway. I did the whole "revert to parent" / "revert to inherited" thing, which is found in many blogs. I was

MVC 3 Razor page encoded as utf 8 shows encoded characters

心不动则不痛 提交于 2019-12-22 08:40:11
问题 I have a VirtualPathProvider which takes source code from my DB as a plain string and encodes it as UTF8. For example: public override Stream Open() { MemoryStream result = new MemoryStream(); result = new MemoryStream(Encoding.UTF8.GetBytes(_sourceCode)); return result; } I then have a layout master page which has its charset as UTF 8 <meta charset="utf-8"> The master page then calls @RenderBody() which gets my VirtualPathProvider page and outputs it to the browser. The problem is that it is

Asp.net MVC with Entity, using jquery to pass data into List. Does not work

主宰稳场 提交于 2019-12-22 08:39:39
问题 Edit 3 / Final This is the fully working example using .NET MVC, Jquery and editor templates. https://www.dropbox.com/s/t4yxbhkuowyd7va/exerciseTest.rar Edit 2 It finally works ! Thanks to the answer below. It appears that i needed to change the NewAnswerRow partial line: <input type='text' id='Answers_@(Model.AnswerId)__Answer' name='Answers[@Model.AnswerId].Answer'/> Thanks ! Edit 1: I've followed this guide: http://www.techiesweb.net/asp-net-mvc3-dynamically-added-form-fields-model-binding