Change the error class of asp-for in .NET Core’s MVC

This is a problem I ran into when converting my Bootstrap 3 based site to MDB which is based on Bootstrap 4.

The validation class in MDB is is-invalid as opposed to input-validation-error. I think it’s because of Bootstrap as opposed to MDB itself. But, in any case I had to change it with minimal code.

One solution is given here.

Adding the @Html.FieldHasError(m => m.Password) in the class attribute of every input seems to be too much work. So, here is my solution that uses TagHelper instead of extension methods on IHtmlHelper.

[HtmlTargetElement("input", Attributes = "md-for", TagStructure = TagStructure.WithoutEndTag)]
public class MdInputTagHelper : InputTagHelper
{
    public MdInputTagHelper(IHtmlGenerator generator)
        : base(generator)
    {
    }

    [HtmlAttributeName("md-for")]
    public ModelExpression MdFor 
    {
        get => For;
        set => For = value;
    } 

    public override void Process(TagHelperContext context, TagHelperOutput output)
    {
        base.Process(context, output);

        var fullName = NameAndIdProvider.GetFullHtmlFieldName(ViewContext, For.Name);

        if (ViewContext.ViewData.ModelState.TryGetValue(fullName, out var entry) && entry.Errors.Count > 0)
        {
            output.AddClass("is-invalid", HtmlEncoder.Default);
            output.RemoveClass("input-validation-error", HtmlEncoder.Default);
        }
    }
}

Now, to use the class invalid-feedback in your inputs you have to do a single change, replace asp-for in the input tag with md-for.

<div class="md-form">
    <i class="fas fa-envelope prefix"></i>
    <input md-for="Input.Email" class="form-control">
    <label asp-for="Input.Email">Your email</label>
    <span class="invalid-feedback" asp-validation-for="Input.Email"></span>
</div>

One last thing, remember to import the tag helper in your _ViewImports.cshtml file:-

@addTagHelper Maxotek.WebAppUtils.Helpers.MdInputTagHelper, Maxotek.WebAppUtils

Fake Amazon Orders to get town Blacklisted

So, I read this article about the planned strategy of a group of traders in Ulhasnagar to bombard Amazon with a bunch of fake orders. Their justification for doing the same is that Amazon is discounting product prices and killing their business, that it would lead to loss of jobs and an eventual loss to the country’s economy because Amazon pays less in taxes.

As an entrepreneur myself I understand that business is a competition. As a business owner you are always looking to grow your business. At times some companies (especially startups) find totally new markets and thrive. But, most business is still in established markets. A lot of big names with a lot of capital enter these markets and try to undercut the leaders. This can be by building better products, offering better service or in a country like India with the “Kitna deti hai” (the bang for your buck) mentality.

Amazon has built a better service by allowing people to choose from a wide variety of products and order them from the comfort of their homes. You don’t have to stand in queues or drive to the supermarket. Reviews by other buyers help you choose (or not) a product. The delivery for prime orders is super quick, more so if you live close to Mumbai, Delhi, or Bangalore. The free shipping is a gimmick, though. Prices for most Amazon Prime items are higher than alternatives available from other sellers. Basically, they seem to include the shipping price and the cost for a better service. But, I believe it is worth it. Besides, it is still cheaper than your brick and mortar stores.

The loss of jobs is a lie. The products are still made by indian companies. Instead, more jobs have been created because of the hiring of a ton of delivery executives and other Amazon staff. Sure they are underpaid. But, it is better than being underpaid. The whole wealth distributuion is a problem that warrants a longer discussion.

Unlike a lot of these traders, Amazon does pay taxes. Sure, every company tries it’s best to minimize taxes and maximize profit. But, they are way more compliant to the government regulations.

Placing fake cash on delivery orders might work initially for these traders. But, in the long run Amazon will find ways around it. Perhaps they will only allow prepaid orders in such localities. The country is moving more towards digital currency anyways.

Amazon is not the only player, there is Flipkart which is backed by Walmart. Both of these companies have more than enough money to weather the storm and drive the traders to the grave. Then you have stores focused on a subsection of the retail market – Myntra, Zabong, Zivame to name a few. Adidas has their own online store where you can get items at a huge discount. I personally have seen the same item at a 50% discount when compared to Adidas’s store here in City Centre, Kolkata. All you have to do is pick a shoe model that is about 7-9 months old. What innovation happens in shoes in 9 months? It’s not Intel’s constantly shrining processors!

Ultimately, it is almost impossible to slow down the technology Technological revolution. Even Elon Musk has given up on convincing the world to slow down Artificial Intelligence and think about our safety first. I said almost because there could always be that extinction level event (ELE), similar to the one that wiped out the dinosaurs!