I am creating a form which will be used to nominate multiple people from a various teams for an award. There is no limit on the amount of people that could be nominated so it is hard to say how many nominee info I should add to the form. I am curious if there is a way to create a nominee info i.e. Full Name , Email , etc with an option too "add another nominee" where the user could specify more than one person info on the form without submitting multiple forms. Also user should be able to edit or view the already added nominee info's
Example:
About your nominee:
Nominee's Name: Steve
Nominee's email : steve#gmail.com Nominee's
Country : drop down list
add another nominee
You could create a form (or a modal popup) with a Html Table, an Add button and a Submit Button.
The Html Table is used to store the nominee information.
The Add button is used to dynamically add rows in the Html Table, inorder to add new nominee information.
The Submit button is used to submit the nominees. Use JQuery to loop through the table and post the list of entities to the action method.
More detail information, please check the following links:
Dynamically add rows to HTML Table in ASP.Net MVC
Pass (Send) List of objects from View to Controller using jQuery AJAX in ASP.Net MVC
Related
I'm using ASP.NET MVC to create a web application and have stumbled upon a situation where I'm not sure what the best solution would be.
I have a users page where I am simply loading a list of users and their roles into a table. The roles are checkboxes, for example Manager and Administrator are two separate roles that are expressed as checkboxes on that row for the user.
In the far right column is an Actions field with 3 buttons: Save, Change Password and Delete.
Change Password works by opening a dialog box and hitting an action on the Controller called ChangePassword, this is a Post request as the form is in a different area and some values are set to hidden fields using JavaScript.
Delete works by calling an action called Delete which is a Get request where in the view the action parameters are explicitly set by using the values from the Model. Since these values aren't going to change I can safely do something like this:
#Url.Action("Delete", new { loginName = Model.Users[i].LoginName, username = Model.Users[i].Username })
However, the Save action is different because the save action is meant to be used to update the user roles, which the user can change by selecting different checkboxes. My initial plan was to make the Save action a Get request and have the values passed in similar to how I do this with Delete but I would need to set some sort of hidden field using JavaScript so that I know which fields are updated.
An alternative solution would be to have every table row a form and make Save a Post action and have the values from the checkboxes bound to the model on the action. I'm not sure whether this would be advised because this could potentially mean 50+ forms on the page depending on how many users I have.
I'd appreciate some advice on this issue.
Thanks
A GET request should never change the state of your application, i.e. it shouldn't delete or modify users.
I'd use the ASP.Net Membership Provider and call its respective methods in the Controller Actions.
I am working in a project that have a Person model. I display the Persons in an Index action with a table, showing Checkboxes allowing to select multiple people.
The user is supposed to be able to do different things to the selected people, like:
Approving them for access.
Sending an email message.
The action of approving them for access is just making a database change. The action of "Sending an email" should redirect to another page that would request the details of the email so it can be send.
So far we have a table inside a Form that have the people. That form is posting to one action and I am able to retrieve the selected IDs. So far so good.
My issue is that I would like the form to post to different routes dynamically (if the user clicks on the action to "approve" the user to go to one place, if the user clicks on the actions to "send email" to go to another place).
I haven't been able to find how to dynamically modify the form action to post to a different Url on runtime. Is there any way to do that? (or maybe I am doing all this wrong, and I should, somehow, collect the IDs with jQuery and post to the Urls that I want).
What you need to do is to change (on the client, using javascript) "action" attribute of the form element:
var url = ...
$("form").attr("action", url);
I am new to asp.net C#. How can I create a form where a user can fill out a couple of text fields (page name for instance) and then create a new page on submit. Then they would be able to select the page from a select box and go to it to add content.
I don't know how to implement this and I do not need a full on CMS.
You can create the form to enter the values into a sql table. so, for instance you'd have a title text box, a content text box, and then a button. In your button action you will enter that data to the table.
then you can create a navigation that for intance - to keep it very simple - does a select all titles from table name. you'll have these titles as your pages. so, upon clicking the title you'd have a script to bring up the details.
This is a very simple overview of how you can create pages.
since you said you are new I'd recommend going through some tutorials. I highly recommend plural sight http://www.pluralsight-training.net/microsoft/
hope this helps!
Multiple forms submit with C# MVC.
The company I work for has taken the approach of having multiple forms submits being done using jquery submitting different forms on different button clicks. My concept should be pretty simple. I have a text box sitting in a form that holds the quantity of items to purchase. I have two separate buttons, one for adding to cart and one for adding to wish list.
The jquery submits the form, but the formcollection in the MVC code does not have any form data.
Is My jquery not submitting the form? Or not submitting the hidden fields?
if you are sure form is submitted then i suppose there is some problem in the view. all inputs should be submitted for sure, even if they are not visible (e.g. style="display:none;"). i could be more specific if i would see the view.
Check the Action signature in the Controller and be sure that you're using the right parameters' name.
Just for curiosity, why you're not using ajax for this ? (#Html.BeginAjaxForm () )
How do you populate data coming from SQL server based on users request?
Example:
I have a page with about 50 links(all user links) and I want to be able to have the user click on their link and bring another page(template I believe) with all their data. The catch here is that I don't want to create 50 pages(one of each user).
How can I accomplish this in ASP.NET C#?
Its simple as creating an aspx page and a model.
Profile.aspx - this page contains all the view display for the current user or the requesting user. You can pass the user id through the link you had. Example:
John Doe
Now in the page load or the controller (MVC) - code behind you can use that id to retrieve the details of the user and start to populate to your aspx page. Example:
txtName.Text = UserModel.Name
Or if your are using MVC for the web application it will be easy as naming the controls and setup the model in your view aspx.
I think this site could get you started: http://www.asp.net/mvc/tutorials
There should be very similar examples to what you would like to do. Explaining it here would just duplicate existing good material.
If you are completely new to programming, try a C# tutorial first, for example: http://www.csharp-station.com/Tutorials/Lesson01.aspx