c# - How do i bind the variable value to the view page at runtime in mvc 4 -


this serious issue i'm facing quite long time 3 hours, suppose no fix found , i'm stuck. here have developed patient registration page in asp.net mvc 4 razor posting form data database if validation comes out true, before need call random variable object storing random value within prespecified range , insert variable view typed(connected patients model class) ,

created create template such fields or properties of patients class acessed in view store patients data view. now,here need random value (patient's id) preselected patient id textbox each time patientregistration page called works unique token generator every new patient registered.

i have tried several other codes bind random value form element patient id none of them worked me.below i'm writing code model class,controller , regisrtation view(cshtml).please me in this!

patients model class:-

using system; using system.collections.generic; using system.linq; using system.web; using system.componentmodel; using system.componentmodel.dataannotations;   namespace onlinedoctorapppointment.models {      public class patients     {           //public string patientid { get; set; }         [displayname("patient name")]         [required(errormessage = "patient name required")]         [stringlength(100, minimumlength = 3)]         [regularexpression("^([a-z][a-z]+([ ]?[a-z]?['-]?[a-z][a-z]+)*)$", errormessage = "only alphabets required")]         public string patientname { get; set; }          [displayname("patient age")]         [required(errormessage = "age required")]         [range(0, 100, errormessage = "age must between 0 , 100")]         public int age { get; set; }          [required(errormessage = "please enter email address")]         [datatype(datatype.emailaddress)]         [display(name = "email address")]         [maxlength(50)]         [regularexpression(@"[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}", errormessage = "please enter correct email")]         public string patientemail { get; set; }          [displayname("patient mobile number")]         [required(errormessage = "please enter mobile number")]         [regularexpression(@"(\+)?(91)?( )?[789]\d{9}", errormessage = "please enter correct format")]         public int patientmobileno { get; set; }          [displayname("password")]         [required(errormessage = "please enter password")]         [regularexpression(@"(?=(.*[a-z])+)(?=(.*[0-9])+)[0-9a-za-z!#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~]{8,15}", errormessage = "your password must contain minimum 8 characters consisting of atleast 1 numeral , alphabets")]         public string patientpassword { get; set; }          [displayname("patient id")]         public string patientid         {             get;             set;         }     } } 

patient registration .cshtml:-

@model onlinedoctorapppointment.models.patients  <!doctype html>  <html> <head>     <meta name="viewport" content="width=device-width" />     <title>patientregistration</title> </head> <body>     <script src="~/scripts/jquery-1.8.2.min.js"></script>     <script src="~/scripts/jquery.validate.min.js"></script>     <script src="~/scripts/jquery.validate.unobtrusive.min.js"></script>      @using (html.beginform())     {         @html.antiforgerytoken()         @html.validationsummary(true)          <fieldset>             <legend>patients</legend>              <div class="editor-label">                 @html.labelfor(model => model.patientname)             </div>             <div class="editor-field">                 @html.editorfor(model => model.patientname)                 @html.validationmessagefor(model => model.patientname)             </div>              <div class="editor-label">                 @html.labelfor(model => model.age)             </div>             <div class="editor-field">                 @html.editorfor(model => model.age)                 @html.validationmessagefor(model => model.age)             </div>              <div class="editor-label">                 @html.labelfor(model => model.patientemail)             </div>             <div class="editor-field">                 @html.editorfor(model => model.patientemail)                 @html.validationmessagefor(model => model.patientemail)             </div>              <div class="editor-label">                 @html.labelfor(model => model.patientmobileno)             </div>             <div class="editor-field">                 @html.editorfor(model => model.patientmobileno)                 @html.validationmessagefor(model => model.patientmobileno)             </div>              <div class="editor-label">                 @html.labelfor(model => model.patientpassword)             </div>             <div class="editor-field">                 @html.editorfor(model => model.patientpassword)                 @html.validationmessagefor(model => model.patientpassword)             </div>              <div class="editor-label">                 @html.labelfor(model => model.patientid)             </div>             <div class="editor-field">                 @html.editorfor(model => model.patientid, new { @value = viewbag.patientid })                 @html.validationmessagefor(model => model.patientid)              </div>              <p>                 <input type="submit" value="create" />             </p>         </fieldset>     }      <div>         @html.actionlink("back list", "index")     </div> </body> </html> 

using system; using system.collections.generic; using system.linq; using system.web; using system.web.mvc; using onlinedoctorapppointment.models;  namespace onlinedoctorapppointment.controllers {     public class logincontroller : controller     {         //         // get: /login/          public actionresult login()         {             return view();         }         public actionresult patientlogin()         {             return view();         }         public actionresult doctorlogin()         {             return view();         }         public actionresult patientregistration()         {             random random = new random();             int patientid = random.next(1000, 100000);              viewbag.patientid = patientid;             return view();         }      } } 


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -