Judging from the structure of the sentence, there is nothing wrong with it. But if you analyze this sentence, there is just something minor that is missing. Perhaps, it would be better if we add the word "the" before the word "students". So the sentence would be, "It can be dangerous to carelessly teach grammar to the students."
But, I would choose option B if I need to.
I hope this answer helps!