I am trying to write a code that takes the last name and first name from user input and stores the values in a data table with MVC4. I have added the following code under Accountcontroller.cs
that will create a submit button. Once the user clicks the submit button it would add the user input to the data set.
private void button_Click( object sender, EventArgs e)
{
SqlConnection cs = new SqlConnection("Data Source = FSCOPEL-PC; ....
SqlDataAdapter da = new SqlDataAdapter();
da.insertCommand = new SqlCommand(" INSERT INTO TABLE VALUES ( Firstname, Lastname, )
}
I have also added the following code under logincs.html that will create the submit button, once the user logins.
<button type="submit" id="btnSave" name="Command" value="Save">Save</button>
We examine four ways to create forms in ASP.NET MVC 5: weakly typed synchronous forms, strongly typed synchronous forms, strongly typed asynchronous forms, and using jQuery AJAX to post form data.
Html. ActionLink creates a hyperlink on a view page and the user clicks it to navigate to a new URL. It does not link to a view directly, rather it links to a controller's action.
In MVC you have to create a form and submit that form to the Controller's Action method. The syntax for creating form given as:
View:
@using (Html.BeginForm("YourActionName", "ControllerName"))
{
@Html.TextBoxFor(m => m.FirstName)
@Html.TextBoxFor(m => m.LastName)
<input type="submit" value="Submit Data" id="btnSubmit" />
}
Controller:
public ActionResult YourActionName(UserModel model)
{
//some operations goes here
return View(); //return some view to the user
}
Model:
public class UserModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With