|
I wouldn't know, but there should be mounds of evidence, one way or the other. Maybe ask the pupals still in school.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
(Actual (non-programming) question at the bottom)
There's this thing that's been bothering me for a while now.
We've got Razor Pages in .NET Core, which has some really cool features (if you're happy with good old forms rather than SPAs).
For example, having a property such as the following:
[Required]
[StringLength(64, MinimumLength = 1, ErrorMessageResourceType = typeof(Texts), ErrorMessageResourceName = nameof(Texts.StringLengthError))]
public string Name { get; set; } And some Razor syntax like this:
<input asp-for-vue="Name" class="form-control" /> Generates the following HTML:
<input type="text" data-val="true" data-val-length="The Name must be at least 1 and at max 64 characters long." data-val-length-max="64" data-val-length-min="1" data-val-required="The Name field is required." id="Name" maxlength="64" name="Name" class="form-control"> By using resource files, the error messages get translated depending on the language of the user requesting the page.
There's binding between the front-end and back-end (I think through the "name" attribute, but may be the "id" attribute as well).
Pretty sweet!
However, it does absolutely nothing in terms of front-end logic.
If you have a collection, for example, and you need to add an item, Razor Pages is not doing anything for you.
So that's where I wanted to use Vue and that's where the problems start...
Using Razor, you'd do something like this to render the initial list:
@for (int i = 0; i < MyItems.Count; i += 1)
{
<input asp-for-vue="MyItems[i].Name" class="form-control" />
} That renders the complete list in the back-end and you can't use v-for (from Vue) because that will render the whole list again in the front-end!
However, using purely Vue, you'd get something like the following:
<div v-for="myItem in myItems">
<input v-model="myItem.name" class="form-control" />
</div> Now you're missing the data-val attributes as well as the id and name attributes (and thus your binding).
Adding them manually is just a pain and kind of defeats the whole point of using Razor!
Now I've spend my weekend building something that does both.
<div asp-list-for-vue="MyItems">
<input asp-for-vue="MyItems[0].Name" class="form-control" />
</div> Or, if you like your Vue syntax:
<div v-for="(myItem, index) in myItems">
<input asp-for-vue="MyItems[0].Name" class="form-control" />
</div> The generated HTML will be:
<div v-for="(myItem, index) in myItems">
<input type="text" data-val="true" data-val-length="The Name must be at least 1 and at max 64 characters long." data-val-length-max="64" data-val-length-min="1" data-val-required="The Name field is required." :id="'MyItems_' + index + '__Name'" maxlength="64" name="'MyItems[' + index + '].Name'" v-model="myItem.name" class="form-control">
</div> Now, adding an extra item to your list, like so:
myModel.myItems.push({name: ''}); Will automatically trigger some Vue magic and add a new item with id and name set so it will be correctly submitted to the back end.
It even works with nested lists.
Am I the only one who has this problem/wish?
I'm thinking of submitting the code to GitHub (it's not a lot although currently pretty limited) so other people may use it.
Is there any interest for such a solution?
|
|
|
|
|
Sander Rossel wrote: I'm thinking of submitting the code to GitHub as an article
FTFY
|
|
|
|
|
Was thinking about that as well, but I'm polling if people need this first
Could be a nice introduction to extending ASP.NET Core tag helpers
|
|
|
|
|
Sander Rossel wrote: polling if people need this first
When did that ever have anything to do with it.
I wrote my articles mainly for the feedback.
With 14 million users there's bound to be someone that needs it!
|
|
|
|
|
I'm a busy man nowadays, I'm juggling a couple of software projects and writing a-plenty on the side (just not for CP).
I have to pick my battles carefully
Jörgen Andersson wrote: With 14 million users there's bound to be someone that needs it! I guess you're right about that though!
|
|
|
|
|
Seems like excellent material for an article, here !
sheers, Bill
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Pah!
you are 10 days late man!
Forget Razor, forget Vue, use Blazor Web Assembly!
|
|
|
|
|
So much truth in your words...
|
|
|
|
|
at least they tend to be more funny when there is.
With all of the "marriage sucks" jokes lately (a lot of them by one specific member) it makes me wonder why do people bother getting married? Why do people keep getting married if it's such torture?
I've never understood that. Marriage sucks jokes have been around forever yet people keep getting married.
If your marriage is like all of these jokes, I suggest you go to counseling. Marriage does not have to be and should not be torture. It should be the best relationship you ever have. I suppose for some of you, maybe it is torture AND the best relationship at the same time.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Marriage is a religious notion, not biological. Marriage does suck. It has its benefits, but there are more cons than pros, IMHO.
|
|
|
|
|
I got this advice from a friend just before getting married: Marriage solves a lot of problems that didn’t exist before. 😀
|
|
|
|
|
|
Sure, it's religious. It's also political, which is an even better reason to avoid it. But it's also biological: albatross (amongst many other species) mate for life.
|
|
|
|
|
You can "mate for life" without being married.
Maybe not in all countries where marriage is still holy and you have to marry before you can look at a woman, but in the west you can mate all you want without being married
|
|
|
|
|
|
Slacker007 wrote: there are more cons than pros, When done right, marriage is the best way to raise children. Religious or not, biological or not, it has been proven to be the best way to raise kids and to stabilize society.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Because you can't raise children when you're not married?
You can live together and do all the things you'd do when you were married without actually being married.
|
|
|
|
|
Sander Rossel wrote: Because you can't raise children when you're not married? Obviously not.
Sander Rossel wrote: You can live together and do all the things you'd do when you were married without actually being married. That is a true statement.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
ZurdoDev wrote: Obviously not. I can't tell if you're joking or being serious
I'd assume you're joking, but we've proven to have completely different viewpoints and beliefs that aren't always compatible before
|
|
|
|
|
You implied that I had said you can't raise children unless you're married. I'm shocked you would think I'd say something like that or that ANYONE would say something like that. Of course you can raise children even if you're not married. I don't think you read my post very clearly.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
You're right, you said "the best way" and not "the only way".
I still don't think it matters whether you're married or not though, but that's another matter
ZurdoDev wrote: I'm shocked you would think I'd say something like that or that ANYONE would say something like that. I think there are countries where you get jail time or worse when you get kids without being married.
You'll at least be forced to marry (even when it's from rape, just to illustrate the seriousness of the matter).
And it's not even that long ago that his was also the norm in our countries.
Actually, I live in a bible belt where some people still frown upon getting children without being married or even living together without being married.
|
|
|
|
|
Sander Rossel wrote: You're right, you said "the best way" and not "the only way". Correct.
Sander Rossel wrote: I still don't think it matters whether you're married or not though Yes, I know that about you.
Sander Rossel wrote: I think there are countries where you get jail time or worse when you get kids without being married. Extremes are rarely a good thing.
Sander Rossel wrote: where some people still frown upon getting children without being married or even living together without being married. Luckily, that's not just in the Bible belt. But it is a fading practice, unfortunately.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Sander Rossel wrote: You're right, you said "the best way" and not "the only way".
I still don't think it matters whether you're married or not though, but that's another matter
This is much too complex a subject to be covered in a short post, but I'll try...
The problem is that, as the Chinese ideogram for "mother" hints, everyone has a mother. Who the father is, is less certain.
Shorn of the religious part, traditional (m-f) marriage is an attempt to balance between the obligation of the man to support his children and his fear (in the days before genetic testing) that his wife's children are not his, and that therefore he is supporting some freeloader's children. In marriage, a man agrees to support all children born in the marriage, and the woman agrees that her children will only be sired by the man. OTOH, there was no obligation on the man to support children born out of wedlock.
This is one of the reasons why unfaithfulness by the woman was treated much more seriously than unfaithfulness by the man - it consisted possible fraud.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
He didn't say you can't raise children while unmarried, he said doing so while married is the best way.
And he's right - when controlled for all other variables, a child being raised by two parents instead of one tends to do better.
|
|
|
|