Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am trying to develop one asp.net mvc website. where i want to retrieve the textbox value on same page which is inside the table.
How to access that value.
Posted

You can't access the TextBox from the Controller, MVC doesn't work that way. you'll have to submit the form containing the TextBox to the Controller instead if you want the value. The link below shows a way of achieving that:

http://www.asp.net/mvc/tutorials/mvc-music-store-part-5[^]
 
Share this answer
 
Accessing textbox value in controller depends on the parameters your controller method will take.

Suppose your controller will take only one argument then you simply call it by redirecting to the Url of your controller's method name along with argument.

{Controller}/{Method Name}/{Argument}
Employee/Details/EmpID
Employee/Details/12

//controller method looks like
Public ActionResult Details(int EmployeeId)
{ ..... }


Or if your controller will take modal as parameter then prepare json object and pass it to the controller. Using it you can also pass multiple values to controller.

//Javascript code
var employee = { EmployeeId: 12,
                 EmployeeName: StartShining }
  
//Your modal class looks like
Public Class Employee 
{
 Public int EmployeeId { get; set; }
 Public string EmployeeName { get; set; }
}

//Your controller method looks like
Public ActionResult Details(Employee emp)
{ ..... }


HTH
 
Share this answer
 
Add this code in Aspx page
--------------------------------
First Name
<%: Html.TextBoxFor(m=>m.FirstName)%>
Last Name
<%: Html.TextBoxFor(m=>m.LastName)%>
<input type="Submit" value="Submit" />


Add this to Model

Public string FirstName{get; Set;};
Public string LastName{get; Set;};


In Controller u can access

.FirstName
 
Share this answer
 
v2
Comments
[no name] 14-Apr-11 2:52am    
pre tag added.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900