I have this model:
public class LkUpTitleModel
{
[Key]
public int TitleID { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessage = " * Has been left empty")]
[DisplayName("Title")]
[Remote("LkUpTitle", "Treeview", AdditionalFields = "TitleID", HttpMethod = "POST", ErrorMessage = " * Already exists")]
public string Title { get; set; }
}
Tied into this db context
namespace MyWork.DAL
{
public class DataBaseContext : DbContext
{
public DataBaseContext() : base("name = constring")
{}
public DbSet<LkUpGenderModel> vwLkUpGender { get; set; }
public DbSet<LkUpTitleModel> vwLkUpTitle { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
base.OnModelCreating(modelBuilder);
}
}
}
In the controller:
public DataBaseContext db = new DataBaseContext();
This is the class in the function for the remote validation
[HttpPost]
public JsonResult LkUpTitle(string Title, int? TitleID)
{
if (TitleID == null)
{
TitleID = 0;
}
var title = (from g in db.vwLkUpTitle where g.TitleID != TitleID select g).ToList();
return Json(!title.Any(x => x.Title.ToUpper() == Title.ToUpper()));
}
When it runs and tries the validation I get the below error. Not sure why it is looking for dbo.LkUpTitleModel and not dbo.vwLkUpTitle
Server Error in '/' Application.
Invalid object name 'dbo.LkUpTitleModel'.
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.Data.SqlClient.SqlException: Invalid object name 'dbo.LkUpTitleModel'.
Source Error:
Line 135: } Line 136: Line 137: var title = (from g in db.vwLkUpTitle where g.TitleID != TitleID select g).ToList(); Line 138: Line 139: return Json(!title.Any(x => x.Title.ToUpper() == Title.ToUpper()));
Source File: >C:\Users\RLewis\Source\Workspaces\Workspace\Orwell\OrwellFrontEnd\Controllers\TreeviewController.cs Line: 137
Stack Trace:
[SqlException (0x80131904): Invalid object name 'dbo.LkUpTitleModel'.] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction) +2508250 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction) +81 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +606 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4157 System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +58 System.Data.SqlClient.SqlDataReader.get_MetaData() +89 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +369 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest) +2047 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +394 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +240 System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +41 System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) +12 System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext
1 c) +9 System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch(TTarget target, Func
3 operation, TInterceptionContext interceptionContext, Action3 executing, Action
3 executed) +72 System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext) +355 System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior) +167 System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) +12 System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +37[EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details.] System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +112 System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute(ObjectContext context, ObjectParameterCollection parameterValues) +738 System.Data.Entity.Core.Objects.<>c__DisplayClass7.b__6() +97 System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func
1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +288 System.Data.Entity.Core.Objects.<>c__DisplayClass7.<GetResults>b__5() +155 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func
1 operation) +189 System.Data.Entity.Core.Objects.ObjectQuery1.GetResults(Nullable
1 forMergeOption) +280 System.Data.Entity.Core.Objects.ObjectQuery1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0() +11 System.Data.Entity.Internal.LazyEnumerator
1.MoveNext() +45 System.Collections.Generic.List1..ctor(IEnumerable
1 collection) +381 System.Linq.Enumerable.ToList(IEnumerable1 source) +58 OrwellFrontEnd.Controllers.TreeviewController.LkUpTitle(String Title, Nullable
1 TitleID) in C:\Users\RLewis\Source\Workspaces\Workspace\Orwell\OrwellFrontEnd\Controllers\TreeviewController.cs:137 lambda_method(Closure , ControllerBase , Object[] ) +151 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +157 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2 parameters) +27 System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22 System.Web.Mvc.Async.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) +29 System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32 System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3d() +50 System.Web.Mvc.Async.<>c__DisplayClass46.b__3f() +225 System.Web.Mvc.Async.<>c__DisplayClass33.b__32(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34 System.Web.Mvc.Async.<>c__DisplayClass2b.b__1c() +26 System.Web.Mvc.Async.<>c__DisplayClass21.b__1e(IAsyncResult asyncResult) +100 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27 System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +29 System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36 System.Web.Mvc.Controller.b__15(IAsyncResult asyncResult, Controller controller) +12 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +22 System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26 System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10 System.Web.Mvc.MvcHandler.b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +29 System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9720041 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155