I am using ASP.NET MVC 2.0 and I want to transfer my ViewModel properties to business object. I can do this manually or use AutoMapper or use new method available in ASP.NET MVC 2.0. My question is that does anyone know the name of the new method which allows to copy the properties from one object to another?
Got it! But it is part of ASP.NET MVC Futures library! Sorry for the confusion.
ModelCopier.CopyModel(employeeViewModel, employee);
And here is the link:
http://weblogs.asp.net/rajbk/archive/2010/03/31/easy-way-to-update-models-in-your-asp-net-mvc-business-layer.aspx
Related
In the asp.net core projects:
What is the best way to share a controller with MVC Views to another project?
Is it any way to build a controller with Views as a component in the assembly and share it to the different projects.
In other words how to not just simply copy code and how to reuse it to another project.
Yes its a new feature in ASP Core called Application Parts.
It allows you to store your ASP Core Controllers/Views etc in a separate assembly and then you can include/share it as Application Parts/Dlls which is new in ASP Core, the sample code from MSDN is linked above for ASP Core.
In the ConfigureServices method of your Startup class just add this:
// set this up
services.AddMvc().AddApplicationPart(assembly).AddControllersAsServices();
Where assembly is the name of your instance Assembly with your controllers & Services, then you can load it either getting it from any included type or like this:
var assembly = Assembly.Load("YourApp.NameSace.AssemblyName");
Another nice ref implementation and explanation
I am facing a problem with adding two projects in the same solution and both run as a single instance.
Let me explain that in more details. I have MVC project which is the main web application I used in my project now I want to add a new asp.net application to use for rendering reports and get the benefit of using asp.net page with Report Viewer.So, I was thinking in adding a new asp.net application that will contains my reports then map this new pages to my mvc application
The problem is how to deploy these two instances as one application in server.
I know that i can run both applications in debug mode by using debug > start new instance but how i can manage that in server.
Also is there is a way to deal with those two applications as one application
Update:
Using Ihor idea and with the help of this tutorials
How can I use a reportviewer control in an asp.net mvc 3 razor view?
http://msdn.microsoft.com/en-us/library/ms251692%28v=vs.100%29.aspx
I am facing a problem in binding to my object datasource attached to project. For example I have repository for SalesInvoices and I want to use GetData function exists in that repository to bind report with
ASP.NET MVC is built on regular ASP.NET Web Forms. In your scenario you don't need to have a specific different project for Reports, you can have Reports inside your MVC project. For example you can add a new GenericReport.aspx under some folder (for example "Reports") of your MVC project.
Then when user requests some action on your site you can use PartialView with iframe to your GenericReport.aspx. On this page you can add any webforms-specific logic that you need.
To be honest I am not aware of such particular behaviour of reports, but according to the reply: How can I use a reportviewer control in an asp.net mvc 3 razor view? you will probably need to move your data to a separate project. It shouldn't be web application project but a class library (generating .dll) and you can use it in your MVC project.
Using Ihor idea and with the help of this tutorials
How can I use a reportviewer control in an asp.net mvc 3 razor view?
http://msdn.microsoft.com/en-us/library/ms251692%28v=vs.100%29.aspx
I was facing a problem as I noted in updates in original post I solved by adding a class in reports folder contains method with my model Like that
public class ReportModels
{
public List<SalesInvoice> GetData()
{
return null;
}
}
with this way i can map this model to report successfully
Can I use Entity Framework DbContext, Code First approach, Data Annotation validation and customize validation in ASP.NET Web Forms?
You can use Data Annotations present in System.ComponentModel.DataAnnotations with ASP.NET WebForms but only with the new ASP.NET 4.5.
Check this awesome tutorial for complete details:
What's New in Web Forms in ASP.NET 4.5
Exercise 2: Data Validation
There's also a NugGet package that seems to do what you want:
Data Annotations Validator Control for ASP.NET Web Forms
I believe this will be supported in ASP.NET 4. But in the mean time, you can use xVal for WebForms. There are examples and a demo available online.
(disclaimer: this is one of my open source projects)
I am trying to learn MVC. I want to automatically generate the required view code as and when I add a controller. This is possible if I select the option “Controller with read/write actions and views, using Entity Framework” . However I am not using Entity Framework. How can I achieve the similar behavior without using Entity Framework? And why it is unable to automatically generate the view when I don’t use Entity Framework?
Also, is there any good MVC3 tutorial that does not use Entity Framework (with code download available) ?
Reference
How do I configure ASP.net MVC to Scaffold using ADO.net dataservice?
Levergaing T4Scaffolding for WCF Web API
ASP.NET MVC 3 and NHibernate Scaffolding
Scaffold your ASP.NET MVC 3 project with the MvcScaffolding package
Once again LINQ to SQL or Entity Framework for new MVC 3 project
MVC Scaffolding for WCF Services
Create a Dropdown List for MVC3 using Entity Framework (.edmx Model) & Razor Views && Insert A Database Record to Multiple Tables
You might find some of what you're looking for in Steve Sanderson's MvcScaffolding package
Nuget
Install-Package MvcScaffolding
After installing (it will probably install some EF requirements) you could scaffold basic CRUD views for your model as follows assuming a model type MySweetModel
Scaffold Views MySweetModel
Please note this command will not create the controller class, but should create the following views under /Views/MySweetModel
_CreateOrEdit.cshtml
Create.cshtml
Delete.cshtml
Details.cshtml
Edit.cshtml
Index.cshtml
It looks like you might be able to override the default T4 templates, but I've never used MvcScaffolding outside the scope of EF. It's also possible someone has already done this for your persistence layer e.g. NHibernate or whatever you're using. I'd search a bit before implementing your own templates.
I need to use session in my MVC 3 web app like I used to do in my old ASP.NET web app. I need to save some values, and then access it from any of my controllers and all other views.
Please give me a very simple example following the best practices.
I am new in MVC development and started with MVC 3.
You use session the same way you do in webforms.
In your controllers you can simply use the Session object. You could save the state of a model in Session and pass the result to your view.
Basic session usage remains same for both mvc and webforms.
In addition to that you have ViewData, ViewBag also to store between controller and view
Refer to this article for creating a helper class for using strongly typed sessions in mvc.