开发者

How do I populate a textbox with some data in MVC3?

I have a controller (MigrateAccountController) with its own view. It asks for a username and password then does some checking. If the user checks out, I do a return RedirectToAction("Register", "Account", user);.

I want to populate the username and email textboxes with the data contained in user (its a RegisterModel type). I've tried every incarnation that I can think of for the "htmlAttributes". 开发者_JS百科 One example is @Html.TextBoxFor(m => m.UserName), new { value = Model.UserName })

Basically I want to use the same view for two things. If the view is passed a model containing data, then use that data to fill in the textboxes. If the view is not passed anything, then do nothing and leave the textboxes blank. Is this possible or should I split the views?


A RedirectToAction issues a server side redirect which indicates to the browser to issue a new request at the given location. So there is no passing the model between actions using RedirectToAction (the third parameter is for a RouteValueDictionary). Either save the model in TempData, then RedirectToAction and then read the model from TempData in that action. Or why not just return the View instead of redirecting.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜