-
Notifications
You must be signed in to change notification settings - Fork 377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ItemTemplates for Razor Pages #566
Add ItemTemplates for Razor Pages #566
Conversation
{ | ||
"author": "Microsoft", | ||
"classifications": ["Web", "ASP.NET"], | ||
"name": "Razor Page with Page Model", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DamianEdwards @Eilon - do the branding thing plz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not it.
"groupIdentity": "Microsoft.AspNetCore.Mvc.RazorPageWithPageModel", | ||
"precedence": "100", | ||
"identity": "Microsoft.AspNetCore.Mvc.RazorPageWithPageModel", | ||
"shortName": "page", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideas about a short name to distinguish this from pages (without pagemodel)??
We also have the option to make this a single item and have another parameter to distinguish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd advocate for making these into a single template with a distinguishing param, maybe something like:
"model": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "<insert appropriate desc. here>"
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll give this a try thanks
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
||
namespace MyApp.Namespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does the right thing. Relax.
"primaryOutputs": [ { "path": "Index.cshtml"}, { "path": "Index.cs" } ], | ||
"defaultName": "Index", | ||
"symbols": { | ||
"namespace": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably good to add a description to the namespace symbol, it'll get displayed in the detailed help for the template in the CLI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tentative-approval. Others will need to approve other stuff.
{ | ||
"author": "Microsoft", | ||
"classifications": ["Web", "ASP.NET"], | ||
"name": "Razor Page with Page Model", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not it.
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a good default set of namespaces? Anything else common that should go here? (Not at all saying it isn't, I'm just not familiar with what's generally used.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For templates, we generally only include the usings that are required by the generated template code. But I could see including additional usings that most users would end up adding as they modify the content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same set of namespaces that the template uses for HomeController
with the Microsoft.AspNetCore.Mvc.RazorPages
namespace added (required).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me then.
{ | ||
public void OnGet() | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitespace? Is this a joke?
87ea568
to
951743f
Compare
"sources": { | ||
"modifiers": [ | ||
{ | ||
"condition": "(no-pagemodel)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seancpeters - this isn't working. I've tried some stuff and it still wants to output the Index.cs
file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I screwed up the syntax when we were chatting. Sources should be like this:
"sources": [
{
"modifiers": [
{
"condition": "(no-pagemodel)",
"exclude": [
"Index.cs"
]
}
]
}
],
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add item templates for _ViewStart.cshmtl
and _ViewImports.cshtml
too?
|
||
namespace MyApp.Namespace | ||
{ | ||
public class Index : PageModel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls name this IndexModel
and the file Index.cshtml.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@model Index | ||
@*#endif*@ | ||
@{ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don'twe usually include blank lines at the end of template files? I think it makes it easier to start adding HTML, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't usually know. Added a blank line
] | ||
}, | ||
"symbols": { | ||
"namespace": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rynowak - you had asked me about making a parameter required. You can add
"isRequired": "true"
... to the symbol definition to make it required.
Note: I'm tracking down a bug related to isRequired, so you may want to hold off on making that change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I wasn't planning to do it for this change, I just wanted to know.
Sure, I'll do this in a follow up PR |
Generates Page and PageModel, uses a placeholder namespace
Generates Page and PageModel, uses provided namespace
Generates Page |
"identity": "Microsoft.AspNetCore.Mvc.RazorPage", | ||
"shortName": "page", | ||
"sourceName": "Index", | ||
"primaryOutputs": [ { "path": "Index.cshtml"}, { "path": "Index.cs" } ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rynowak - for adding conditions to primary outputs, the format is like this:
"primaryOutputs": [
{ "path": "Index.cshtml" },
{
"path": "Index.cs",
"condition": "(!no-pagemodel)"
}
]
If I understood correctly, that example should do what we talked about earlier.
22ccce8
to
c8e600b
Compare
Updated |
@mlorbetske @seancpeters - Ping. this is ready to go |
b7d681d
to
0b2a60c
Compare
/cc @DamianEdwards @mlorbetske