The view 'name' or its master was not found or no view engine supports the searched locations - asp.net-mvc-5

I'm getting this error message, and any of the advice that I've seen does not appear to be applicable; i.e. all views, controllers and models are in the correct folders.
More detail:
I have a master view, which shows a graphical flowchart-like interface for interacting with the application. The user selects the "Open Study" symbol, and I redirect to another view which allows the user to select a Study to work with.
The OpenStudyController code retrieves the selected study and then redirects back to the master view:
public ActionResult SelectStudy( Guid? id )
{
// code elided for clarity
return RedirectToAction( "ActivateStudy", "Home" );
}
HomeController has a method called ActivateStudy(...), which does get invoked with the appropriate environment:
public ActionResult ActivateStudy()
{
// code elided for clarity
return View();
}
As I said, all views, controllers and models are in the correct folders.
When the "return View()" code in ActivateStudy() is executed, the error message occurs:
Server Error in '/' Application.
The view 'ActivateStudy' or its master was not found or no view engine supports the searched locations.The following locations were searched:
~/Views/Home/ActivateStudy.aspx
~/Views/Home/ActivateStudy.ascx
~/Views/Shared/ActivateStudy.aspx
~/Views/Shared/ActivateStudy.ascx
~/Views/Home/ActivateStudy.cshtml
~/Views/Home/ActivateStudy.vbhtml
~/Views/Shared/ActivateStudy.cshtml
~/Views/Shared/ActivateStudy.vbhtml
What am I missing? Some additional parameter in RedirectToAction(...)? Some new entry in RouteConfig?

If you have a _ViewStart.cshtml and it contains something like the following you do not need to specify the same layout in each view.
#{
Layout = "~/Views/Shared/_Layout.cshtml";
}
I believe your problem might be related to a missing slash. In your comment you said that your view contained the following line:
Layout = "~Views/Shared/_Layout.cshtml"
I think that needs to have a slash after the tilde.
Layout = "~/Views/Shared/_Layout.cshtml"
But, as I said, you should be able to remove that line entirely.

Well, I don't know if this is the "right" way to do it, but, in my HomeController.ActivateStudy() method, I return the Home "index" view:
public ActionResult ActivateStudy()
{
// code elided for clarity
return View( "Index" );
}
And this works.
It's at times like these where you realize you really don't know very much. Back to the books and code editor. Learn by doing.

Related

How can I know the retained class name or keyword when I use navigation framework in Android Studio?

The following code is from the project at https://github.com/mycwcgr/camera/tree/master/CameraXBasic
The project use the latest navigation framework, I find there are some retained class name such as CameraFragmentDirections, GalleryFragmentArgs.
The system have no prompt information for these class name, must I remember these keywords by myself?
Code
/** Method used to re-draw the camera UI controls, called every time configuration changes */
#SuppressLint("RestrictedApi")
private fun updateCameraUi() {
// Listener for button used to view last photo
controls.findViewById<ImageButton>(R.id.photo_view_button).setOnClickListener {
Navigation.findNavController(requireActivity(), R.id.fragment_container).navigate(
CameraFragmentDirections.actionCameraToGallery(outputDirectory.absolutePath))
}
}
/** Fragment used to present the user with a gallery of photos taken */
class GalleryFragment internal constructor() : Fragment() {
/** AndroidX navigation arguments */
private val args: GalleryFragmentArgs by navArgs()
}
No you do not need to remember these things by yourself, if you know of a trick.
For example, if you don't remember the "keyword" Directions, but you know you want to do something related to CameraFragment, you can start typing e.g. CameraFragm in Android Studio. It will then suggest CameraFragment and CameraFragmentDirections for you. That way you can find CameraFragmentDirections easily even though you did not remember the keyword Directions.
There are not that many keywords to worry about though. After working with the Navigation framework for a while, you will remember them all.
If you are curious, you can find the generated classes here after a build:
./app/build/generated/source/navigation-args/...
e.g. after a debug build:
./app/build/generated/source/navigation-args/debug/com/android/example/cameraxbasic/fragments/CameraFragmentDirections.java
If you are even more curious, the code that generates these classes is here:
https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/navigation/navigation-safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/java/JavaNavWriter.kt
There you can for example find this code:
internal fun Destination.toClassName(): ClassName {
val destName = name ?: throw IllegalStateException("Destination with actions must have name")
return ClassName.get(destName.packageName(), "${destName.simpleName()}Directions")
}
which is the code that decides what name CameraFragmentDirections gets. (Note "${destName.simpleName()}Directions" at the end.)

Export to Excel from grid - no data

I am getting an Excel spreadsheet with columns but, no data when I click on the Excel icon on a grid.
I have put a grid on the CR306030 page that is tied to a view of a custom DAC that relates back to the CRActivity record for the page. I have set the SkinID to Inquire and the AllowImport = true. The view in my Graph extension class looks like this:
[PXImport(typeof(CRActivity))]
public PXSelect<MyDac,
Where<MyDac.activityNoteID,
Equal<Current<CRActivity.noteID>>>> MyDacView;
I'm not sure what I am missing. I am trying to export the data in the grid so, I may be way off here.
TIA!
This happened because I had an update() call inside of a FieldSelecting() event handler. This, for some reason, caused the export to quit working. This presents another problem for me that I will post in another question but, the export issue is resolved. Here's what my code looked like in the extended graph that was causing the issue:
protected virtual void CRActivity_UsrCustomField_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{
CRActivity activity = (CRActivity) e.Row;
CRActivityExt activityExt = activity.GetExtension<CRActivityExt>();
// Some code here.
e.ReturnValue = TotalValue;
activityExt.UsrCustomField = TotalValue;
Base.Events.Update(activity);
}
I changed it to this in order to get the export working:
protected virtual void CRActivity_UsrCustomField_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{
CRActivity activity = (CRActivity) e.Row;
CRActivityExt activityExt = activity.GetExtension<CRActivityExt>();
// Some code here.
e.ReturnValue = TotalValue;
//activityExt.UsrCustomField = TotalValue;
//Base.Events.Update(activity);
}
Adding Export button is all that should be required. Setting SkinID to inquire will do that for you.
It seems you are running into an uncommon scenario so I would suggest to rollback tentative solutions like adding Import functionality that isn't required in case your implementation has errors causing conflicts with export functionality.
Next issue I would suspect is a kind of security/rights issues or an explicit call to disallow exporting records. Removing unnecessary code and substituting the DAC you are using could help expose the root cause as some specific entity could have been locked down by security while others aren't.
If you're familiar with Acumatica web services it could be worth a shot to test if records from the grid can be retrieved by web service. If they can't then that points towards security/rights issues.

Pluralsight Advanced - Movie Content not displayed in Content table

I am walking through Pluralsight Advanced Orchard course.
I just created the Movie module and created a sample movie.
It was working fine but I did notice that the sample movie did not show up in Manage Content page.
I can only get to the list by going to Content Definition and select "List Items"
Then I can see the list of Movie item
This is what I got so far. I followed the steps and don't see what I have missed. I did notice that Orchard has changed slightly from 1.4 to 1.10 appearance wise. I wonder if this also has something to do with the version difference.
Any tips would be appreciated! Thank you
namespace Pluralsight.Movies {
public class Migrations : DataMigrationImpl {
public int Create() {
ContentDefinitionManager.AlterTypeDefinition("Movie", builder=>
builder.WithPart("CommonPart")
.WithPart("TitlePart")
.WithPart("AutoroutePart")
.WithPart("BodyPart")
.Creatable()
.Draftable());
return 1;
}
public int UpdateFrom1()
{
ContentDefinitionManager.AlterTypeDefinition("Movie", builder =>
builder.WithPart("BodyPart", partBuilder=>partBuilder.WithSetting("BodyTypePartSettings.Flavor", "text")));
return 2;
}
}
Try to add .Listable() into your type definition. Note that if you already ran those migrations, unless you reset the database, it won't execute again, so you'll have to put it into a UpdateFrom2() method.
Note that this setting can also be checked from the content definition screen after the fact.
Note: I think the PluralSight course was written at a time when this setting didn't exist, and everything was listable.

Is it possible to use T4MVC with Attribute routing (RoutePrefix/Route)?

Are attribute-based routes supported by T4MVC in some way?
I have applied a RoutePrefixAttribute to my MVC 5 controller and a Route attribute on my action. T4MVC, as it stands, does not seem to provide routes based on these attributes. The route that it provides is the convention-based routes of /Area/Controller/Action.
Folder structure is:
/
Areas
Ratio
Controllers
RatioSet
PresetGroupController.cs
Views
RatioSet
GroupDetails.cshtml
Controller:
[RoutePrefix("Ratio/RatioSet/Preset/Group")]
public partial class PresetGroupController
{
[Route("Details")]
public virtual ActionResult Details()
{
//.....
return View(MVC.Ratio.RatioSet.Views.GroupDetails, model);
}
}
Now, if I try the following:
return RedirectToAction(MVC.Ratio.PresetGroup.Details());
I get a 404 error, because the requested URL is:
<app_root>/Ratio/PresetGroup/Details
which is the "default" route, rather than the correct attribute-specified:
<app_root>/Ratio/RatioSet/Preset/Group/Details
So, does T4MVC only work with the convention-based routes, inferred from the folder structure, and not any routes that are specified via attributes?
I know this is an old question, but I had the same problem and ended up fixing it adding the RouteArea attribute to the Controller.
Something like this:
[RouteArea("Ratio")]
[RoutePrefix("Ratio/RatioSet/Preset/Group")]
public partial class PresetGroupController
{
[Route("Details")]
public virtual ActionResult Details()
{
//.....
return View(MVC.Ratio.RatioSet.Views.GroupDetails, model);
}
}
Have you verified that the non-T4MVC equivalent is working? If so, what does that line look like?
Note that T4MVC really doesn't generate routes itself, but instead calls into standard MVC framework methods to do this. See section 1.1 in the docs.
My guess is that you're running into an issue that is unrelated to T4MVC. e.g. see this issue where the problem is the order of registration calls.

Orchard Custom User Part is not stored in Database

I can't seem to store additional data in a separate contentpart attached to User. I have done the following:
Created a module
In the module I created a Model for ProfilePart and ProfilePartRecord
In the migration I created a table for ProfilePartRecord (from type ContentPartRecord)
In the migration I altered the typedefinition for User, by setting WithPart ProfilePart
I created a driver class, that has 2 edit methods, one for get and one for post (code snippets are below
I also created a handler that adds a storage filter for profilePartRepository of type ProfilePartRecord
Module Structure
Drivers/ProfilePartDriver.cs
Handlers/ProfileHandler.cs
Models/ProfilePart.cs
Models/ProfilePartRecord.cs
Views/EditorTemplates/Parts/profile.cshtml
Migrations.cs
Placement.info
Since I think the issue is in the Driver. This is my code:
Is it going wrong because the part is attached to User? Or am I missing something else.
public class ProfilePartDriver:ContentPartDriver
{
protected override string Prefix
{
get { return "Profile"; }
}
//GET
protected override DriverResult Editor(ProfilePart part, dynamic shapeHelper)
{
return ContentShape("Parts_Profile_Edit", () =>
shapeHelper.EditorTemplate(TemplateName: "Parts/Profile", Model: part, Prefix: Prefix));
}
//POST
protected override DriverResult Editor(ProfilePart part, IUpdateModel updater, dynamic shapeHelper)
{
updater.TryUpdateModel(part, Prefix, null, null);
return Editor(part, shapeHelper);
}
}
I have used Skywalker's blog. There is one chapter about registering customers by using the User and adding your own content parts to it. Worked nice for me.
First of all - is your ProfilePart editor shown at all when you go to Dashboard and edit a given user? I noticed you're using Parts_Profile_Edit as a shape key, but actually use EditorTemplates/Parts/Profile.cshtml as a template. It's perfectly correct, but note that Placement.info file uses shape keys, so you have to use Parts_Profile_Edit as a shape name in there. Otherwise it won't get displayed.
Second - have you tried debugging to see if the second driver Editor method (the one for handling POST) is being called at all?
Like Bertrand suggested, I'd look into one of the existing modules that work (afaik there is one for user profile in the Gallery) and see the difference. It might be something small, eg. a typo.

Resources