Offline template rendering similar to MVC partial views? - c#

I want to refactor an existing MVC action so that it can be used offline to build email content.
The action just fetches a model by Id and hands it over to the view, where the view renders it's fields. There is a foreach loop in the view.
My first thought was to just create an html file and do string search and replace in it.
Is there any template rendering libraries I should consider instead?

You may take a look at RazorEngine.

Related

Customized View + Update Form using ASP.NET MVC5

I am new to ASP.NET MVC5 and already familiar with adding a scaffold item using MVC5 Controller with views using the Entity Framework.
Is there a way I can customize the web pages like this:
where I can split the existing records (first tab has 5, second has 4, and so on...) from the database on different tabs and update the values once.
Any suggestions?
You can have a master view that gets partial view data via AJAX. Each partial view could have its own model. That way you can split the model logically into many views.
Once the values are changed you can post changes via JavaScript. You can use KnockoutJS to track changes to the model on the client side.
You can use Jquery UI Tabs to display the tabs. cut and paste the razor markup generated by the visual studio to the respective tabs

Accessing a MVC3 view via absolute URL without displaying it

What I try to achieve:
Convert a MVC3 view to PDF with abcpdf 8.
It is a result view where I want to cut off party of the views DOM like navigation and other website related parts.
Abcpdf needs, in order to render the html with all css formattings correctly, a absolute url. But I don't want to show the result-pdf view to the user. So how can I access a view from controller by URL without displaying the view. The original result view shall be displayed all the time.
Thank you in advance
Christian
You cannot access a View directly with MVC, you have to go through a Controller method. In ASP.NET MVC, URLs map to Controller methods, not to Views.
So if you know the URL of the Controller method that calls the View, you can take that URL and pass it to ABCPDF.

MVC Page Template Configuration in the View file itself?

I want to render an MVC Page/View that will have varying widgets on the page. So some views might have Widget A, another page could have Widget A and B, etc. I was thinking each widget would be a partial view that I want to pass parameters. So if it was a weather widget, I would need to pass the partial view the Zip code etc.
My question is what the best way to approach this architecturally? We currently have an external xml file that stores this info: myview.xml (for myview.cshtm)
We don’t want to have an external file, but would like to store everything in one place maybe in the header of the view file itself? Any recommendations?
Independent widgets on your views?
Sounds like you just need to use RenderAction to render them.
More info by Haack
MSDN

Integrate Markitup text editor to ASP.NET MVC project

I'm trying to add markitup text editor with markdownsharp http://markitup.jaysalvat.com/home/ to my MVC ASP project and kindof confused how to go about it. I added a class from markdownsharp and tested the function. that is working fine but confused how to embed the editor in my view.
Using Visual Studia 2010. Please guide regarding the same.
The documentation contains many examples.
#user488652:
As MarkItUp uses jQuery to transform a DIV into a complex editor, I am having similar issue binding the TextArea to the Model in my view.
There is one option I thought of, and it may be a better option, all things considered: make the form an AJAX-style form.
You would use jQuery to handle the Click on the Submit Button. When submitted, your handler would gather the model data and the MarkItUp editor data and fire it off to a controller action in JSON format via $.ajax().
Your controller then would receive the JSON, parse it into your objects, and use the MarkdownSharp library to do whatever logic you need, then send off the objects to your data layer for persistence.
The result may actually be better than the traditional MVC Form binding.
Good solution?

How do I attach a link (to a View) to an image in ASP.NET MVC?

Ok, so here is my situation. I am creating a web application using ASP.NET MVC 2 using the C# language. I have programmed in HTML, CSS, and PHP for several years and I am very new to ASP.NET. The part that I am having trouble with is the image gallery.
The setup: I have a link on the navigation bar that goes to a "Galleries" page. This page will show a list of galleries. Each gallery has a title, an image, and a description. All of this information is pulled from an XML file. I'm using the XML file like a database. I wanted to use this method so that i could easily update the list of galleries and have the updated XML file automatically be reflected by the website. Now, the galleries should link to an "Images" page. This page will display a list of images within the gallery based on what gallery was selected. This page will also pull from an XML file.
The problem: I cannot seem to attach a dynamic link to the image? I am also stuck and not sure how to get the correct View to display. I know I need to do something with the controllers and models, right? I have some code if needed? I would greatly appreciate any help or direction for this! Thanks!
For the image, as long as you have the collection of images in the Model for the page, you can loop through each element and do something like:
<a href="<%= Html.Encode(image.Url) %>" />
When it comes to the Views, there's some auto-magic that happens behind the scenes to map you Controller to the View.
Scott Guthrie has a good post on the inner workings of the ASP.NET MVC Framework and the different methods that it uses to go from your Controller to your Views:
ASP.NET MVC Framework (Part 1) - ScottGu's Blog
I would much rather create an Html Helper for that. That way you can write something more along the lines of this:
<%= Html.ImageLink("<url to image">) %>
Feels like a cleaner solution to me then having to write out an anchor tag. Either way will work, though.
For more info on writing custom Html Helpers:
http://www.asp.net/Learn/MVC/tutorial-09-cs.aspx

Categories