|
when I'm trying any one of these Getting Error ..pls help
public ActionResult Index()
{
/* Mapper.CreateMap();
var dbContext = new WorkTraningEntities();
var emplist = from employee in dbContext.Employees select employee;
var emps = new List();
if (emplist.Any())
{
foreach (var employee in emplist)
{
EmpEntity empModel = Mapper.Map(employee);
emps.Add(empModel);
}
}
return View(emps);*/
var config = new MapperConfiguration(cfg => cfg.CreateMap<Employee,EmpEntity>());
IMapper mapper = config.CreateMapper();
var source = new Employee();
var dest = mapper.Map<Employee,EmpEntity>(source);
Mapper.AssertConfigurationIsValid();
return View(source);
}
Error is :
The model item passed into the dictionary is of type 'MvcAutoMapperDemo.Employee', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[MvcAutoMapperDemo.Employee]'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'MvcAutoMapperDemo.Employee', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[MvcAutoMapperDemo.Employee]'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: The model item passed into the dictionary is of type 'MvcAutoMapperDemo.Employee', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[MvcAutoMapperDemo.Employee]'.]
System.Web.Mvc.ViewDataDictionary1.SetModel(Object value) +608383
System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary) +371
System.Web.Mvc.WebViewPage1.SetViewData(ViewDataDictionary viewData) +50
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +98
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +294
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +15
System.Web.Mvc.<>c__DisplayClass1a.<invokeactionresultwithfilters>b__17() +23
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 continuation) +242
System.Web.Mvc.<>c__DisplayClass1c.b__19() +25
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) +175
System.Web.Mvc.Async.<>c__DisplayClass2a.<begininvokeaction>b__20() +89
System.Web.Mvc.Async.<>c__DisplayClass25.<begininvokeaction>b__22(IAsyncResult asyncResult) +102
System.Web.Mvc.Async.WrappedAsyncResult1.End() +58
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +44
System.Web.Mvc.<>c__DisplayClass1d.b__18(IAsyncResult asyncResult) +15
System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +16
System.Web.Mvc.Async.WrappedAsyncResult1.End() +58
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +54
System.Web.Mvc.Async.<>c__DisplayClass4.<makevoiddelegate>b__3(IAsyncResult ar) +16
System.Web.Mvc.Async.WrappedAsyncResult1.End() +58
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +44
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +12
System.Web.Mvc.<>c__DisplayClass8.b__3(IAsyncResult asyncResult) +25
System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +16
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +58
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +44
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +11
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9734909
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1532.0
|
|
|
|
|
The error is self-explatory. Your view expects a list of Employee objects so it will be something like
@model IEnumerable<Employee>
yet you are passing only a single Employee object. We can't tell you how to resolve this as we don't know your business rules. If your view caters for multiple employees but you only want to pass one employee then change the action to something like
return View(New List<Employee>{source});
|
|
|
|
|
As the error suggests , you are passing Employee Entity whereas it expects IEnumerable.
|
|
|
|
|
2 partial views connect to index view but first partial view have display data(name,datein,compliant where status = "new") and the submit button.once click the submit button (the status value changed to "Received")refresh the page and display the same data(name,datein,compliant)
if u have any examples related this can u plz send me or guide me if u have any idea.thankyou all who r helping me.
|
|
|
|
|
You have already posted this question, received an answer, and accepted the answer:
In MVC how two partial view connect to indexview[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The partial view just needs a form around the submit button etc whose action points to the action that generated the parent view and whose method is post. Submitting the form then posts the data to that action which will process it and return the view as normal.
This is all incredibly basic MVC stuff, you'd be best going through a book on MVC to learn the basics and how to do these things will become clear.
|
|
|
|
|
use of select command to fetch(Resume) Record into table
|
|
|
|
|
|
Not clear. what you exactly want ?
|
|
|
|
|
Hi..Im Beginner in asp.net mvc4..pls can you help me ..im trying to learn AutoMapper using EF..can you provide me your valueable guidance ..how to code AutoMapper..
im getting the error..
Missing type map configuration or unsupported mapping.
Mapping types:
Dept -> DeptEntity
MvcAutoMapper.Models.Dept -> MvcAutoMapper.Models.DeptEntity
Destination path:
EmployeeEntity.Dept1.Dept1
Source value:
(null)
in Advance thanks for Help..
modified 13-Apr-16 5:34am.
|
|
|
|
|
|
Thanks Richard MacCutchan..
|
|
|
|
|
Tip: in future try Google first.
|
|
|
|
|
Create one class. Declare different function
To bind the data using datagridview control. And also add hyperlink to the Grid.
|
|
|
|
|
Is that supposed to be a question?
|
|
|
|
|
What is it ? what you want to do ? or you want to tell us something ? Please elaborate
Find More .Net development tips at : .NET Tips
The only reason people get lost in thought is because it's unfamiliar territory.
|
|
|
|
|
public class One
{
public void Different(GridView gv, string url)
{
gv.DataBind();
gv.Caption = url;
}
}
There ya go; exactly to spec.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
I want to view .dwg files in asp.net c# simple applications..How can read .dwg files in asp.net c#.
rajesh kumar
|
|
|
|
|
ASP.Net does not have a native way of doing this. I suggest looking for a browser plugin or some 3rd party tool that will help you do this.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
All the new features of MVC can be implemented by using ASP.Net (it may be tedious way / we may need to write lengthy code to achieve it) then why we need MVC?
e.g.- DAL is there is MVC and ASP.net both
Code behind can be reused by creating Modular coding.
We can return results as per customer need in ASP.Net / WCF.
Viewstate is bulky but we can disable it.
then Why MVC?
|
|
|
|
|
You have to create 2 or 3 MVC projects to really appreciate it. I thought the same thing until project 3 of mine, now I'm not going back to web forms. One of my questions was why use Razor, it's stupid. Now I use Razor as much as I can.
There's just too many reasons why to list here.
For me, I can write windows apps that can access an MVC websites data, read and write.
I've done it in Web Forms, but MVC was way faster to write for me.
And I really like the DAL, Model, Controller part of MVC. For me the View is just another way to output from the controller.
|
|
|
|
|
When you say asp.net you mean webforms, as MVC is still asp.net.
One of the main advantages of MVC is something that people don't really take advantage of, but more of your code is unit-testable as the layers have a greater separation. With webforms your code-behind isn't really testable, but with MVC it is. It also makes your code easier to use\share with ajax calls as the concept of returning html in partialviews is easier to leverage than getting your user controls to return html.
It's just a different presentation paradigm really, and it has its "downsides" too, namely that the page elements out of the box are limited to html elements whereas webforms comes with all manner of rich controls. It also requires a better understanding of html and http which webforms hides from you so people going from webforms to MVC can struggle with that too. A lot of people go from webforms to MVC and their first question is essentially how to use a gridview that has adding\updating\deleting features etc, and people who ask questions like that should just stick to webforms.
|
|
|
|
|
Hey Guys,
I am working on a MVC project and I am having few issues with textbox lost focus event.
First I have a form there are four textboxes field, on first text box we need to pass name of the employee but we have called this textbox lost focus event to populate all records of Employee if it is already in the database but I am having problem when I pass name in the textbox and clicking "save" button then first textbox event called to check if record exist in the database or not then I need to reclick button once again to save my records if not exist.
So in that case I have to click button twice.
Please help with your thoughts I do not want user to click twice.
Thanks
|
|
|
|
|
Parveen Singh wrote: I do not want user to click twice. Then you need to correct your code.
|
|
|
|
|
which jquery event are you using it for?
|
|
|
|