SET ASP.NET MVC4 button value -


I am a newbie. My problem is that I have a button and I want to set the value from ASP.NET variable .

& lt; Input type = "button" id = "mybt" value = "& lt;% = student.name% & gt;" / & gt;

This code is not working.


Code:

  & lt;% var product = (IEnumerable & lt; Demo.Models.Product & gt;) ViewBag.Products;% & gt; ; & Lt; / Div & gt; & Lt; Div & gt; & Lt; Table range = "1" & gt; & Lt; TR & gt; & Lt; TD & gt; Id & lt; / TD & gt; & Lt; TD & gt; Name & lt; / TD & gt; & Lt; TD & gt; Price & lt; / TD & gt; & Lt; / TR & gt; & Lt;% foreach (different product in product) {%> & Lt; TR & gt; & Lt; Td style = "width: 68px; height: 20px" & gt; & Lt;% = product.id% & gt; & Lt; / TD & gt; & Lt; Td style = "width: 120px" & gt; & Lt;% = product.Name% & gt; & Lt; / TD & gt; & Lt; Td style = "width: 120px" & gt; & Lt;% = product.price% & gt; & Lt; / TD & gt; & Lt; Td style = "width: 120px" & gt; & Lt; Input type = "button" value = '& lt;% = product.id% & gt;' / & Gt; & Lt;%}% & gt; & Lt; / TD & gt; & Lt; / TR & gt;  

Instead, try & lt;% = student.name%> Use this: @ Student name

provided the "Student" is the model name and "Name" is the property that you want.

The reason for this is because <% =%> works for ASPX but there is no razor view engine that you have chosen for your MVC solution.


Comments