c# - changing a role with html select box asp.net mvc4 -
I am using the asp.net web application template and trying to play a role while registering a user I am
& lt; Fieldet class = "col-lg-> 5. Cole-MD-5" & gt; & Lt; Legend & gt; Registration Form & lt; / Legend & gt; & Lt; P & gt; @ Html.LabelFor (M = & gt; m.UserName) @ Html.TextBoxFor (M => m.UserName, new {@class = "Form Control"}) & lt; / P & gt; & Lt; P & gt; @HTMLLabelFor (M = & gt; m password) @HTMLPasswordFor (M => M. password, new {@ class = "form-control"}) & lt; / P & gt; & Lt; P & gt; @ Html.LabelFor (M = & gt; m.ConfirmPassword) @ Html.PasswordFor (M => m.ConfirmPassword, new {@class = "Form Control"}) & lt; / P & gt; & Lt; P & gt; @ Html.DropDownListFor (model = & gt; model.Type, model. Type list) & lt; / P & gt; & Lt; Input type = "submit" value = "register" class = "btn btn-default" /> & Lt; / Fieldset & gt;
model
public class register model {[required] [display (name = "user name")] public string username {get; Set; } [Required] [StringLength (100, ErrorCode = "{0} must be at least {2} character long.", MinimumLength = 6)] [Data Type (DataType.Password)] [Display (name = "password ")] Public string password {get; Set; } [DataType (Datatype password)] [Display (name = "Confirm password")] [compare ("password", error message = "password and no confirmation password match.")] Public string ConfirmPassword {Get; Set; } Public string type {get; Set; } Public IEnumerable & lt; SelectListItem & gt; TypeList {Get Return New List & lt; SelectListItem & gt; {New selection list item {text = "athlete", value = "athlete"}, new selectionistism {text = "coach", value = "coach"}}}; }}} Administrator
[HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public ActionResult Models {if (ModelState.IsValid) {/ Try to register / user {try WebSecurity.CreateUserAndAccount (model.UserName, model.Password); Roles. Adult Torroll (model user name, model type); WebSecurity.Login (model.UserName, model.Password); Redirect Action ("Index", "Home"); } Hold (subscribeUseur exception e) {ModelState.AddModelError ("", ErrorCodeToString (e.StatusCode)); }} // If we got this far away, then some failed, see the form return view (model); } I feel as though I'm close, but I can not calm it down and I'm getting this error
Compiler Error Message: Model Registration Manager & gt; A definition for 'DropDownListFor' and the best extension method does not include overload 'System.Web.Mvc.Html.SelectExtensions.DropDownListFor (System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression & gt ;, System. Collections.Generic. Have you started your model in the HTTPGCT register register? Do you have some invalid argument
< P> Like below ... [AllowAnonymous] Public Action Register () {var model = New register MODEL (); View return (model);} I eat one Creating the li template MVC4 app, added your code, the object reference was not set as the default. The Register Model is not to see model object that you are trying to access (i.e. loading TypeInt
in DropDownListFor () Then I have initialized the model in the method given above, all the work is fine, I was able to take a role on the register view.
Check that It helps.
Comments
Post a Comment