Providing a partial view in an ASP.net MVC4 code library? - asp.net-mvc

I've been writing a code library for ASP.net MVC4 I'm called "ExpressForms". The idea is to automate common coding tasks associated with displaying tabular data.
Recently, I started writing code that will automatically display a "filter" widget for each column in the grid so that the user can type to find certain records. The filter automatically adapts to the data type associated with each column and adds a rich set of features, such as autocomplete, and page state bookmarking.
To implement these features, I've created some partial views that the associated classes use to output HTML to render these widgets.
The issue I have is that once someone downloads the library, they must manually copy the partial views to their ASP.net MVC4 project! Is there a way to configure my library (which is a .net class library project) so that a developer who downloads my library doesn't have to manually copy the partial views into his web project?

Related

Generate a View/Page from a model in Blazor with Visual Studio

I am very new to Blazor and i am wondering if there is a way to generate a View from a Model and his Controller like with Razor to develop faster. In Visual Studio it is possible by right clicking on View Folder and choosing the Controller that we want.
Imagine having a User Model with data like Name, Adress etc. In Razor it is possible to generate a View (HTML, JS) containing those attributes related to User by choosing the model that we want (Edit, Create, Delete, etc).Then a complete form will show up with a generated HTML and JS in Pages Folder.
After a whole night of searching I found that this option given by Visual Studio is related with Scafolding and it is only avalaible for Blazor Server Side and Blazor Hosted applications. More information in the Syncfusion documentation

creating Entry form in Umbraco for Add/Edit/Delete/Search functions

This is repeatedly asked many times, however i couldn't find appropriate solution for my problem.
I want to create an Entry Form which will consists of following elements:
Text boxes, drop down fields (auto populated) , check boxes , radio buttons
After my research
i found that i need to create user control, or script file for above form and access it via Macro.
I don't want to use User control as my first preference is to controller-View-Model (i.e. cshtml)
I want to follow MVC approach to create above form. So
1) Do i need to create a seperate project for Add/Edit/Delete/Search Data Entry form?
2) OR i need to create cshtml file for the same(not so clear about this approach)
I'm looking this data entry form with easier for customization and i could use it in other applications as well.
From Umbraco 4.10 up to 6.0.x you can use MVC in Umbraco so there's no need to use an usercontrol. You probably want to use a SurfaceController where you can add any Action you want. The rest is standard MVC (Razor views to build your textboxes, drop downs, ...).
Check out the Umbraco MVC documentation where they explain how to use MVC in an Umbraco project.

ASP.NET MVC3 - Distributing EditorTemplate in library project?

Is it possible to distribute an EditorTemplate control ASCX along with a type in a library project and have it be used by MVC3 when the type is rendered with the EditorFor() method?
Where I work we have a lot of DateTime, Gender and a few more custom fields which have a specific but concsistent way of (HTML) input and a corresponding backing ViewModel type for them (i.e. DateTimeViewModel with separate month, day, year field etc.) and they are in a shared library project.
However we still have to copy the EditorTemplates for these types to each project which is not very DRY.
So is there a way to bundle such EditorTemplate along with the library project and make sure that it's used when the corresponding ViewModel is used without having to copy all EditorTemplate to every projects?
You need a custom VirtualPathProvider to achieve this but nothing out of the box. Here's a blog post you may take a look at.
Disclaimer: Custom VirtualPathProviders don't work with precompiled web applications. So if you intend to precompile your web application before shipping don't use virtual path providers.
Because of this limitation personally I use custom NuGet packages that allow the developers to pull all the necessary templates to their corresponding locations.
You could create your own VS Template, Export it and distribute it to all of your developers I think.
Write Templates for VS2010
You can register your own VirutalPathProvider implementation:
HostingEnvironment.RegisterVirtualPathProvider(new YourViewProvider());
Then you will be able to get your files from basically anywhere (for example from embedded resource).
Hope this helps.
I think this is not currently possible. ASP.NET MVC editor templates should be defined in a partial view file. There is no way to define them in code only.

ASP.NET reference a LINQ to SQL class in Silverlight from its origin in the models of MVC?

I am working on an mvc app that uses some silverlight to supplement a page and instead of having to maintain two separate linq to sql classes I want to add a reference to the main project from the silverlight project but this can't be done through the normal method of just adding a reference, anyone have a workaround?
The normal way to do this is to create a new Silverlight class library project, and use "add as link" to add the existing files from your non-Silverlight project. You can then reference the new project in your main Silverlight project without duplicating any of the files.
Note that if you want to add the LINQ to SQL classes, just add the generated .designer.cs file to the new project--AFAIK dbml files themselves aren't supported in Silverlight projects. You will also need to stub out the L2S attributes present in the classes: ColumnAttribute, FunctionAttribute, and so on.
This may be more trouble than it's worth--if your goal is to communicate with the server using classes generated from a database, you might consider using the Entity Data Model with ADO.NET Data Services (the combination of which is intended for this purpose) instead of LINQ to SQL.

Render View (or Partial) In another project?

i have a solution with the following two projects - MyNamespace.Services and MyNamespace.Web.
Web contains a MVC web application.
In the Service project i have a EmailService class that takes care of sending out emails to the user.
I want to use either a partial or a view (ascx or aspx) for email templates.
I have found several solutions on how to render a partial view and get the result as a string which works fine if the template is inside the web project (as it is a controller in the web project that calls the email service).
(the 2 methods i am trying to use is either http://developersisland.blogspot.com/2009/01/renderpartial-to-string-in-aspnet-mvc.html (at the bottom of the blog) or http://www.brightmix.com/blog/how-to-renderpartial-to-string-in-asp-net-mvc/)
But my email templates are located in the Services project.
How can i refference the path to the templates (partial/view) in my Service project from inside the Web project, that works with either LoadControl or RenderPartial which both takes a virtual path as a parameter ?
It seems like no matter what i do the root directory is set to the Web projects directory.
Is it possible ?
Would be nice to be able to make it work independently of the web project somehow.
I don't think this is possible without developing your own view engine. The default view engine will only look in certain locations for the partial view -- which includes the current view folder and the shared views folder. I don't think you can search for views outside the current project since those views aren't registered with the view engine.
You can consider just creating your HTML helpers to render emails and return it as a string.
Doesn't really matter whether it is partial view or a method returning a string with HTML. i actually think that for your case helper methods would be a better choice.
A simple helper method is also more flexible in the ways you can use it.
You could try creating a custom view engine locator or virtual path provider. Here are a few examples that may help you get going:
Views in seperate assemblies in ASP.NET MVC
Grouping Controllers with ASP.NET MVC
How to use virtual path providers to dynamically load and compile content from virtual paths in ASP.NET 2.0
All of the links above are good, this might help as well. you will certainly be able to get it to find and use the views. The problem I had was in working with them, there was no code completion etc in the other projects. It was semi possible to get that as well by fiddling around with the project file but to be honest I ended up going with the Grouping solution above
Plug in architecture for ASP.NET MVC

Resources