First look at a set of code:
View Code:
@model mvctest.controllers.test@{Layout = null;}<!DOCTYPE HTML><HTML><Head> <Metaname= "Viewport"content= "Width=device-width" /> <title>Form submission</title></Head> <Body> <formMethod= "POST"Action=""> <inputname= "Tester"value= "@Model. Tester" /> <inputtype= "Submit" /> </form> </Body></HTML>
Model class:
Public class test{ publicboolgetset;}
Controller code:
Public ActionResult Formpost () { new Test (); true ; return View (model);}
The question is what is the value of the input property named Tester in view? It is believed that many people will think it is true, but the result is value.
Also put Model.tester in other HTML tags, the value will correspond to its attribute one by one.
<id= "id" name= "name"></span >
So how to solve this problem? Take a look at the following code:
<name= "Tester" value= "@Model. Tester.tostring ()"/>
The string interpretation for the bool type conversion is "to convert the value of this instance to its equivalent string representation (" True "or" False "), as
It is not difficult to understand that Model.Tester.ToString returns TRUE. But why not just return true? This could be razor.
This is how the picture is handled. There is no such situation in ASP.
Here to thank the Park Friends (519740105) for their help, the problem was resolved.
How MVC forms Bind properties or variables of type bool