I have an MVC2 page that includes the following
Left Image
Right Image
When I save this page, I should be able to look at Request.Files to get the two file referenced. But the list is empty.
On the other hand, if I look at Request.Form, the two fields (for BackFile and FrontFile) are present.
Now, this portion of the form is part of the form that is partially updated when other selections on the form are made.
When I have had javascript references in such cases, I have had to also update the javascript references whenever I did a partial update of the page.
But there is no javascript reference to the "input" buttons. Still, I'm wondering if somehow, the "system" is losing the connection between the fields and their buttons and consequently not associating the input fields with files.
I don't know how to get around this.
Specifically is there a way I can proceed by using the values in Request.Form to do the uploads?
First: You cannot use the values from the Request.Form
Second: Did you change the enctype of the form as below:
<form action="home/upload" enctype="multipart/form-data" method="post">
<input type="file" name="uploader"></input>
<input type="submit" value="Save"></input>
</form>
Thrid: I you have a form as above you can create an action method in the controller like below
public class HomeController
{
[HttpPost]
public ActionResult UploadPictures(int id, HttpPostedFileBase ProductPhotoFileUpload)
{
//handle file save
return View();
}
}
Forth: The partial update should not matter
Related
I build some form analogously to:
http://tutorials.jenkov.com/angularjs/forms.html
It means that I also use ng-model as chosen value. These values are retrieved from database - there are multiselect options.
<form>
<input type="text" name="firstName" ng-model="myCtrl.firstName"> First name <br/>
<input type="text" name="lastName" ng-model="myForm.lastName"> Last name <br/>
</form>
Controller {
constructor() {
this.firstName = getFirstNameFromDatabase();
}
}
It is sketch of my code - I wouldn't like to show it here.
It is working ok - values are retrieved from database and displayed as proposition in form.
My issue is following:
Let's assume that someone type in this form "abc". Then, someone click button next (it direct to another state, user is directed to another view - lets denote it X).
User can return from X view with back button. I would like to display "abc" (so my app should memorize chosen values).
However, if user type value "abc" and return to menu (or another else state (view) - different from next button) - in this case value shouldn't be memorized.
Can you give me some clues ?
Since you're actually switching pages in your application, you're going to have to put their content in some sort of persistent storage. A couple ideas pop into my head.
Temporary Browser Storage / Cookies
Server-side storage in a Database or Cache
Either way, you'll need to store the data whenever the user manipules the values. And when they switch pages, choose whether to clear the data or not based on whether it's your special view.
Or another idea is to use an angular function to change the url (rather than a simple anchor). Then in that function you can persist the data before switching to your view. But if they go to a different page, it won't get saved. This only works if they navigate based on your page's links.
Usually this sort of thing is accomplished using a single page which includes both your original view and the next view. You can swap out the content using JS so the user doesn't know the difference. So that's still an option too.
I am trying to create exactly same form given in this fiddle
steb by step angular form
but whenever i click on the next button data entered in the first step resets.. how can i prevent this? On submit all data is undefined while reading in javascript.
Please help me..
In the JsFiddle code you provided you are not retaining the users data, meaning that data is being Binded to anything in the controller. So when leave the section the data is removed.
To retain data make the following changes:
// In your controller add the following object to the $scope
$scope.user = {}
// In your HTML code add the following to your input fields
<input type="text" id="teamName" ng-model="user.teamName" placeholder="Team Name" />
Notice the ng-model tag in the input field this is what binds your data to the user object within your controller
Heres a working JsFiddle, please note that I only updated the Team Name field. Type something in the Team Name field and go to the next section and it will retain your data. You will need to update the remaining fields.
How do I create a form-submittable web component?
Background:
I have a customer-picker component that is basically a text input plus a tiny button to the right of the text box plus a dialog that pops up when the button is clicked. It is used in the same way as one might use an html select.
This component is used as part of an html form that is submitted in the old fashioned (non-ajax) kind of way. The actual html input is encapsulated privately inside of the customer-picker component.
Problem:
The text input's value is not submitted
I guess I can understand why this is. I suppose this is the desired behavior (otherwise we are breaking encapsulation).
So with all that said, how do I create a submittable web component?
For example, suppose I have a form like this:
<form action="action.jsp">
<input name="date-start"/>
<input name="date-end"/>
<input name="name-first"/>
<input name="name-last"/>
</form>
that gets submitted like this:
action.jsp?date-start=2016-06-01&date-end=2016-06-30&name-first=Joe&name-last=Smith
I would like to create the same form using components like this:
<form action="action.jsp">
<date-range name="date">
<full-name name="name">
</form>
that gets submitted exactly the same way as the example above:
action.jsp?date-start=2016-06-01&date-end=2016-06-30&name-first=Joe&name-last=Smith
I am aware of iron-form. But this solution has some problems.
For one, it does not emulate native form submission very well. In a normal html form, when you submit, the current page is automatically replaced by whatever is returned by the action URL. This doesn't seem to happen with iron-form.
Second. It only allows your component to contribute a single value to the submitted data. In the above mentioned date-range example, I would like two values to be submitted for one component.
I've got a form that fills a table in my database. Now i've added a dropdown to that form where the you can choose a user that should be associated to the rest of the form input. But im still unable to associate the dropdown to the user_id in the table.
I hope i made my issue clear,
The code that i just in my controller was :
public function store(PartRequest $request)
{
Project::find(Input::get('project'))->parts()->create($request->all());
return redirect('parts');
}
where my dropdown had classname:project
I have two models
Address:firstline,secondline
Contact:firstname,lastname
and database tables address and contact respectively. i have to create a view page which should display like below format
first name:
last name:
Address:
First line:
second Line:
NEXT STEP {this button leads to next page}
How to create this view.please explain me with the code
and how to save both the objects in the session after clicking on next step button.and what are the controllers to be written.explain me with the code.
address_controller.php
class AddressController extends AppController {
var $uses = array('Address', 'Contact');
the above will allow you access to the Contact Model from the Address Controller
then you can save the data from your add function into both tables
$addressData = array(
'id'=>'',
'firstline'=>$this->data['Address']['firstline'],
'secondline'=>$this->data['Address']['secondline'],
'contact_id'=>$this->Auth->user('id')
);
Then save the data with the following code....
$this->Address->save($addressData);
I would recommend that you do a check to make sure that the data actually saved and then proceed onto the normal save method for the Contact model.
if you already have the add.ctp created for the Address and Contact Models, then you can just go to your views->address->add.ctp and copy the form fields and paste them into the views->contact->add.ctp form.
without seeing any of your code, it's hard to tell exactly what your fields will be but should look something like this :
<input name="data[Contact][firstname]">
<input name="data[Contact][lastname]">
<input name="data[Address][firstline]">
<input name="data[Address][secondline]">