asp.net - put textbox and button in mvc razor app -
asp.net - put textbox and button in mvc razor app -
i working on test mvc project , since it's 1st time working in mvc environment lost , different compared asp.net web forms. trying set textbox , button on form, when using <%= html.textbox("name") %>
textbox example, code displays text on screen , not rendered textbox. when using html markup textbox , button can see textbox shouldn't <%= html.textbox("name") %>
right way that? here have here:
@{ layout = "~/_sitelayout.cshtml"; page.title = "welcome web site!"; } <p> asp.net web pages create easy build powerful .net based applications web. come in name: <%= html.textbox("name") %> <input id="text1" type="text" /> <input id="button1" type="button" value="button" /> </p>
which way should go, can go standard html format or doing wrong textbox <%= html.textbox("name") %>
doesn't displayed? in advance, laziale
in add-on previous answers, if referencing model on view page, can utilize razor html helpers lambda expressions.
updated illustration (this update in response laziale's comment):
in models directory have user class:
namespace mvcapplication.models { public class user { public string name { get; set; } } }
in controllers directory, have usercontroller:
namespace mvcapplication.controllers { public class usercontroller : controller { // // get: /user/ public actionresult index() { homecoming view(); } } }
in views directory, have sub-directory named "user" contains "index.cshtml" file:
@model mvcapplication.models.user @using (html.beginform()) { @html.textboxfor(x => x.name) <input type="submit" /> }
mvc/razor create next html:
<html> <head>...</head> <body> <form action="/user" method="post"> <input id="name" name="name" type="text" value="" /> <input type="submit" /> </form> </body> </html>
asp.net asp.net-mvc-3 razor
Comments
Post a Comment