linq to sql - How to return a message from my repository class to my controller and then to my view in asp.net-mvc? -
I use it to check and enter an existing email ID in my table ... This user's How to display a message works just fine when it tries to register with an existing mail ID ....
if (! Taxidb.Registrations.Where (u = & gt; U.EmailId == reg.EmailId) .no ()) {Taxidb.Registrations.InsertOnSubmit (reg); Taxidb.SubmitChanges (); }
and my administrator has it,
registrations .r reg = new registrationBio (); Reg.UserName = Archive ["user name"]; Reg.OrgName = Archive ["organization name"]; Reg.Address = Archive ["Address"]; Reg.EmailId = Archive ["Email ID"]; Reg.Password = Archive ["password"]; Reg.CreatedDate = System.DateTime.Now; Reg.IsDeleted = Convert.ToByte (0); Regrep.registerUser (reg);
Any white section already present in the user with the asp net MVC to show "email id" ...
registerUser
repository method, indicating whether the database has been updated so that the controller action is taken Could:
if (! Regrep.registerUser (reg)) {ViewData ["message"] = string.Format ("{0} already exists", reg.EmailId); }
and display the message in your view:
& lt; Div & gt; & Lt;% = html.Encode (View Data ["Message"])% & gt; & Lt; / Div & gt;
If you are using a properly typed view which is recommended, then you can add a Boolean property to your visual model that will tell you whether the database has been updated:
model EmailId = reg.EmailId; Model.IsEmailExists =! Regrep.registerUser (reg); See Return (Model);
Examine the model value in the view and:
<% if (Model.IsEmailExists) {%> & Lt; Div & gt; & Lt;% = Html.Encode (Model.EmailId)% & gt; Already exists & lt; / Div & gt; & Lt;%}% & gt;
Comments
Post a Comment