7
Answers

how to pass textbox value to multiple formaction in view

Mohana R

Mohana R

7y
222
1
in my view
 
7 textboxes( name,fnamee,lname,dept,addres,phno.courses)
2 formaction (save,update)
when save action perform need to save all the details in main table but while updating i need dept and address value
 
view code
 
<input type="submit" formaction="save" formmethod="save" name="save" value="save"/>
<label>NAME</label> <input type="text" id="name" name="Name" /><br /><br />
<label>fNAME</label> <input type="text" name="fname" /><br /><br />
<label>lNAME</label> <input type="text" name="Lname" /><br /><br />
<label>dept</label> <input type="text" name="dept" /><br /><br />
<label>addres</label> <input type="text" name="addres" /><br /><br />
<input type="submit" formaction="update" formmethod="save" name="save" value="save"/>
<label>phno</label> <input type="text" name="phno" /><br /><br />
<label>courses</label> <input type="text" name="courses" /><br /><br />
 
while updating the values of phno and courses i need the dept and address to update but its not passing the values because i am using two form action
Answers (7)
1
Amit Gupta
NA 16.5k 25.7k 7y
Hey
 
As your base class is Player which was derived by  Warrior and Sorcerer class, just cast your Player class to the respective derive class to access its field.
 
 
  1. static void Main(string[] args)    
  2. {    
  3.       var player = ChooseClass();    
  4.       if(player is Warrior)    
  5.       {  
  6.          var cType = ((Warrior)player).classtype;  
  7.       }    
  8.       else    
  9.         // Do your rest stuff, same as above to cast to access its variable  
  10.       Console.Clear();    
  11.       Console.WriteLine();    
  12.       Console.ReadLine();    
  13. }    
 
Hope that works ! 
1
Nilesh Shah
NA 22.3k 215k 7y
change this line
  1. Player player = ChooseClass(); 
 
to:
  1. var player = ChooseClass(); 
 
once you know by gettype which type of object is created, then you can write the logic accordingly
0
Joshua Hecht
NA 8 629 7y
Hi Nilesh,
 
I've switched type Player to var in the main method, but I'm still in the same situation because the return type of the method is still Player, and it won't accept var as the return type. Therefore, I still can't access the fields of the Warrior/Sorcerer class because it thinks its just a Player.