如何在没有操作方法的情况下重定向到视图
本文关键字:情况下 重定向 视图 操作方法 | 更新日期: 2023-09-27 17:56:50
我想重定向到一个视图,但没有操作方法。因为它不是必需的。
为什么我想这样做。因为您可以删除文件(删除文件)或删除文件夹(删除文件夹)。
我有这个:
public ActionResult DeleteFile(string designId, int fileId)
{
DeleteFileModel DeleteFile = new DeleteFileModel();
TemplateLibraryEntry entry = GetTemplateLibraryEntry(designId, customerSchema);
FileTree tree = CreateTree(designId, entry.FilePath);
FileInfo fileInfo = new FileInfo(tree.Files[fileId].FullPath);
DirectoryInfo directoryInfo = new DirectoryInfo(tree.Files[fileId].FullPath);
if (directoryInfo.Attributes == FileAttributes.Directory) {
//Url.Action(designId, "DeleteFolder");
string directoryName = tree.Files[fileId].FileName;
DeleteFile.DesignId = designId;
DeleteFile.FileName = directoryName;
DeleteFile.Id = fileId;
DeleteFile.ModificationDate = fileInfo.LastWriteTime;
DeleteFile.RelativePath = fileInfo.Directory.Name + "/" + directoryName;
AddFileExplorerBreadCrumb(designId);
}
else {
string fileName = tree.Files[fileId].FileName;
DeleteFile.DesignId = designId;
DeleteFile.FileName = fileName;
DeleteFile.Id = fileId;
DeleteFile.ModificationDate = fileInfo.LastWriteTime;
DeleteFile.FileSize = fileInfo.Length;
DeleteFile.RelativePath = fileInfo.Directory.Name + "/" + fileName;
AddFileExplorerBreadCrumb(designId);
}
return View(DeleteFile);
}
因此,如果它是一个用户想要删除的目录,那么它会查看:DeleteFolder,如果用户想要删除一个文件,那么它会转到:删除文件。但是怎么做呢?
谢谢
您需要将返回语句放入if和else部分
If( your directory delete condition){
Your directory delete logic
return view("deletedirectory.cshtml");
}
else{
//File delete logic
return view("deletefile.cshtml");
}
如果我
正确理解了您的问题,您正在尝试在调用"删除"操作后显示一种确认页面,并且您想指定哪个页面(文件与目录),而不必为每个页面创建操作。
您可以通过在 View() 方法中指定所需视图的名称来执行此操作。
return View("DeleteFileConfirmation.cshtml", model)
或
return View("DeleteFolderConfirmation.cshtml", model)