I have an attendance system in which the user enters the manual entry for attendance . I dont want to do a single entry and post the form.
The user will enter the Employee ID and then the Date and the time when he attended the office.
The the user will press the Add button it will not be added in the database but it will collect the values in input boxes like this
<input type="text" name="EMP_ID" value="">
<input type="text" name="DateTime" value="">
<input type="Submit" value="Add">
As soon it press the Add button the jquery will append the div box with the form elements
like this
<div class="appendBox">
<input type="text" name="time[emp_id][1][timein]" value="2014-02-02 2:00"/>
<input type="text" name="time[emp_id][1][timeout]" value="2014-02-02 2:00"/>
<input type="text" name="time[emp_id][1][Manual]" value="true"/>
</div>
when all the entries added then the submit button will appear and when submit is pressed it will get the array . I have done this in php ..
I want to achieve this in Asp.net MVC3 .
I want to create a model and fetch the values and insert it in the database
I am confused how to achieve . it
I think this is what you are looking for:
model binding to a list
also duplicate of this: Post array in ASP.NET MVC 2 using name="array_name[]" for form elements
Related
So I have a basic crud that displays information on ASP.Net using entity framework. When i click details it shows the information for that row on a table. I've input a button and a label that when is clicked shows a number, when clicked again it will show the next number higher. It's basically to just a button counter written with JQuery. My question is, is there a way to save this number? I want to store the data in the program so it doesn't forget the number when I move to a different page.
Here is the JQuery.
var count = 0;
function Count() {
count++;
$('#lblShow').text(count);
}
<div>
<input type="submit" name="btnCount" value="Add Signature" onclick="return Count();" id="btnCount" /> <input type="submit" name="btnCountSoc" value="Post to Social Media" id="btnMedia" />
<span id="lblShow"></span>
</div>
Any advice would be appreciated, thanks.
You can use cookies like :
var counter = $("#foo").val();
document.cookie = "counter="+counter";path=/";
I'm trying to login to a website that has authentication form
<form name="logon" action="login.php" method="POST" >
<input type="text" name="id_num" value="">
<input type="password" name="password" value="">
<input type="submit" value="התחברות" name="connect">
</form>
I also snipped the data with Data Tamper.
Data Tamper shows the the keys and values and for connect is shows %D7%94%D7%AA%D7%97%D7%91%D7%A8%D7%95%D7%AA that is the url encoding for that word.
I'm unable to login with C# code apprerantly because of the submit button with the Hebrew value.
any help?
Create a View Model for this form with a property for the submit. Then, upon processing, check to see if the value for the submit property is null.
Thanks for checking.
I am building a web application using angularjs. i have two buttons one will do a Ajax post to server using angularjs and the other will to a normal html post to server. the reason i want the second one to do a direct post to server is that i want to generate an excel document on server and return it tp user to download on response.
please how can i disable angularjs from capturing my form submit for the secont submit button
I'd say that the simplest way is to change the button that shouldn't post the form to not be a form button, but another element that doesn't have that default behaviour. That is, change this:
<form>
<input type="text">
<input type="submit" ng-click="doStuff()" value="Ajaxy things">
<input type="submit" value="Real post">
</form>
to:
<form>
<input type="text">
<a ng-click="doStuff()">Ajaxy things</a>
<input type="submit" value="Real post">
</form>
And style the a to look like a button.
On the current website I am working on we have a Html Form that wraps everything and is used by the global search to submit and search when the user presses enter in the "global search" text box.
The problem we are now having is that we have a application form which has its own text boxes within this Html Form and when you press enter it does a onSubmit for the Global Search.
So in short I was wondering if there was any way to change certain specific text boxes to do a different onSubmit than the global search.
Many Thanks,
Vincent Kong
Instead of using type="submit" buttons use regular buttons (type="button") then call javascript to do what you want.
you can use HTML5 formaction Attribute:
<form action="demo_form.asp">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit"><br>
<input type="submit" formaction="demo_admin.asp" value="Submit as admin">
</form>
Although this quickly becomes messy, you can set the CommandName attributes on each of your buttons and handle them appropriately (based on the command value of the clicked button) during the postback.
I have a single form in ASP.NET MVC (v1) that has 2 input buttons. Each submit button has to be contained within this single form and I need to know which one the user pressed.
I know about the trick to check the FormCollection values which will be returned based on the button pressed. For example, if I have and and the user clicks Button2, I should be able to say Request.Form["Button2"] != null and that will evaluate to true in which case I know that the user clicked that button.
However, this is not working for me. The values of all my buttons is null as non of them are contained within the Request.Form values. Is there a bug in ASP.NET MVC which swallows these values?
Here is my form code:
<% using (Html.BeginForm()) {%>
<% Html.RenderPartial( "EditAreaControl", Model ); %>
<div class="form-layout-command-container">
<div class="form-layout-command-area-alpha"><button type="submit" name="submit1" value="Save">Save</button></div>
<div class="form-layout-command-area-alpha"><button type="submit" name="submit2" value="SaveAndCopy">Save and Create Copy</button></div>
<div class="form-layout-command-area-beta"><%= Html.ActionLink("Cancel", "list") %></div>
</div>
<% } %>
Here is my controller code:
[AcceptVerbs( HttpVerbs.Post )]
public ActionResult Add(FormCollection values )
{
if (values["submit1"] != null)
// always false
if (values["submit2"] != null)
// always false as well
}
From w3schools:
Important: If you use the button element in an HTML form, different browsers will submit different values. Internet Explorer will submit the text between the and tags, while other browsers will submit the content of the value attribute. Use the input element to create buttons in an HTML form.
It seems that this is not standardized. You should stick to
<input type="submit" name="submitButton" value="Save" />
<input type="submit" name="submitButton" value="Cancel" />
I would use inputs of type submit instead of buttons. Non-inputs may not passed back in a form post or at least can be passed back inconsistently. Note that they can have the same name with different values so that you can use the same parameter for any button that submits the form.
<input type="submit" name="submitButton" value="Save" />
<input type="submit" name="submitButton" value="SaveAndCopy" />
public ActionResult Save( string submitButton, ... )
{
if (submitButton == "Save")
{
...
}
else if (submitButton == "SaveAndCopy")
{
...
}
....
}
Using Firebug, I found that the submit buttons were not being sent in the response and because of that, there isn't much I can do on the MVC side. I decided to use a client side hack to populate a hidden input field on the client side which would be passed to the controller values.
I changed the input buttons to be:
<input type="submit" value="Save" onclick="actions.copyValues($(this), $('#submitAction'));" />
<input type="submit" value="Save and Copy" onclick="actions.copyValues($(this), $('#submitAction'));" />
<input type="hidden" id="submitAction" name="submitAction" />
The jquery script simply copies the values:
Actions.prototype.copyValues = function(from, to) {
$(to).val($(from).val());
};
The controller action then looks for the hidden input values:
var request = HttpContext.Request;
return request.Form["submitAction"];
This solves the issue from above but I realize it is not that clean.
Put them in two different forms and you will know which one submitted based on which action was called on the controller.