11

I want to add v-on:click or @click in like following html helper method:

@Html.TextBoxFor(x => x.ItnScanCaseCode, new { @id="txtid",@click = "onchangeevent();" })

How to do that?

Anik Saha
  • 4,313
  • 2
  • 26
  • 41

2 Answers2

13

You could use a Dictionary for htmlAttributes like this:

@Html.TextBoxFor(x => x.ItnScanCaseCode, htmlAttributes: new Dictionary<string, object> {
    { "v-on:click", "onchangeevent()" },
    { "id", "txtid" }
})
adiga
  • 34,372
  • 9
  • 61
  • 83
-3

You just have to use an underscore rather than a - razor will replace it with a hyphen. its a simple as that!!!

@Html.TextBoxFor(x => x.ItnScanCaseCode, new { @id="txtid",v_on:click = "onchangeevent();" })
Kelso Sharp
  • 972
  • 8
  • 12
  • @AnikSaha Then your doing it wrong https://stackoverflow.com/questions/2897733/hyphenated-html-attributes-with-asp-net-mvc https://riptutorial.com/asp-net-mvc/example/7318/adding-a-custom-attribute-with----hyphen--in-name – Kelso Sharp Mar 06 '19 at 20:04
  • 1
    There is difference between hyphen and colon . – Anik Saha Mar 07 '19 at 12:33