Reputation: 3472
I am getting an error saying the view Update has not been found, I wanted to show the TaskDetail view not the update view...
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Update(int taskid, string status)
{
if (!status.Equals("closed", StringComparison.OrdinalIgnoreCase) &&
!status.Equals("opened", StringComparison.OrdinalIgnoreCase))
ModelState.AddModelError("", "incorrect status, please try again");
if (!this.ModelState.IsValid)
return TaskDetail(taskid);
if (status.Equals("Closed", StringComparison.OrdinalIgnoreCase))
_service.CloseTask( taskid, true);
else
_service.CloseTask(taskid, false);
this.FlashInfo("success, task status has been updated...");
return RedirectToAction("TaskDetail");
}
Exception:
$exception{"The view 'Update' or its master was not found. The following locations were searched:\r\n~/Areas/Tasks/Views/TaskManager/Update.aspx\r\n~/Areas/Tasks/Views/TaskManager/Update.ascx\r\n~/Areas/Tasks/Views/Shared/Update.aspx\r\n~/Areas/Tasks/Views/Shared/Update.ascx\r\n~/Views/TaskManager/Update.aspx\r\n~/Views/TaskManager/Update.ascx\r\n~/Views/Shared/Update.aspx\r\n~/Views/Shared/Update.ascx"} System.Exception {System.InvalidOperationException}
Task Detail: (this is inside the same controller)
[HttpGet]
public ActionResult TaskDetail(int taskid)
{
var loggedonuser = _repo.GetCurrentUser();
var companies = _repo.All<Company>();
var users = _repo.All<User>();
var task = _repo.Single<InstructionTask>
(x => x.TaskID == taskid && (x.CompanyID == loggedonuser.CompanyID || x.AssignedTo.Contains(loggedonuser.CompanyType.ToString())));
var dto = new TaskDTO
{
TaskID = task.TaskID,
Title = task.Title,
Description = task.Description,
DateCreated = task.DateCreated,
IsClosed = task.IsClosed,
CompanyID = companies.Where(y => task.CompanyID == y.CompanyID).SingleOrDefault().Identifier,
};
var checkedtags = TaskTagsHelper.GetTags(task.AssignedTo);
var t = TaskTagsHelper.GetPanelTags();
if (checkedtags != null) //if tags are present only then tick them off...
{
foreach (var item in t.Keys.ToList())
{
if (checkedtags.Any(x => x == item))
t[item] = true;
}
}
dto.AvailableTags = t;
if (task.DueDate.HasValue)
dto.DueDate = task.DueDate.Value;
var comments = _repo.All<TaskComment>()
.Where(x => x.TaskID == task.TaskID)
.OrderByDescending(x => x.Timestamp)
.Select(x => new TaskCommentDTO
{
Comment = x.Comment,
Timestamp = x.Timestamp,
CompanyID = companies.Where(y => x.CompanyID == y.CompanyID).SingleOrDefault().Identifier,
UserID = users.Where(y => x.UserID == y.UserID).SingleOrDefault().Login,
Type = EnumHelper.Convert<TaskCommentType>(x.Type)
});
dto.AllComments = comments;
return View(new TaskViewModel
{
TaskDetail = dto,
NewComment = new TaskCommentDTO()
});
}
I am catching the exception here in my base controller:
//Generic methods/ controllers/ attributes will be applied here...
protected override void OnException(ExceptionContext filterContext)
{
//dont interfere if the exception is already handled
if (filterContext.ExceptionHandled)
return;
//let the next request know what went wrong
filterContext.Controller.TempData["exception"] = filterContext.Exception;
//logg exception
//set up redirect to my global error handler
filterContext.Result = new ViewResult { ViewName = "~/Views/Error/PublicError.aspx" };
//advise subsequent exception filters not to interfere and stop
// asp.net from showing yellow screen of death
filterContext.ExceptionHandled = true;
//erase any output already generated
filterContext.HttpContext.Response.Clear();
}
Upvotes: 0
Views: 3940
Reputation: 4998
From what I understand of your code, you are calling the TaskDetail action from the Update method. This is not recommended. Here is why:
If you want it working as it is, you can do this by changing the last line of the TaskDetail to the following so that it knows to always render the TaskDetail view, but I do not recommend it:
return View("TaskDetail", ...viewModel...)
Upvotes: 2
Reputation: 33071
Well the obvious question is:
Do you have a file in one of these folders:
Views\ControllerName\TaskDetail.aspx
Views\ControllerName\TaskDetail.ascx
Views\Shared\TaskDetail.aspx
Views\Shared\TaskDetail.ascx
Where ControllerName is the name of the controller that your Update method is in. That is, if your controller is HomeController, then your folder would be \Views\Home\
Edit:
I'm also a little confused about your ModelState.IsValid call, but mostly because you didn't include the TaskDetail controller action. If your model state is not valid wouldn't you want to return the Update view so the user can correct their mistakes and resubmit? Or are they POSTing from the TaskDetail to the Update action?
Upvotes: 1