I have a html which has some textboxes and a list. I then added paging for my list but whenever I try to click on the next page for list, it reloads the entire page which then results to an error because the page requires an id that becomes null when the paging is cliked. How do I resolve this? I'm using MVC and razor(cshtml).
provide required id in url so that you can get it on other page
for eg.
http:://localhost/abc.html?id=xyz
Related
I have made an app with jQuery mobile and laravel.
On the first page "mobilepage1" if have a form with a next button.
Also some of the form elements are dropdown menu's. The dropdown select options I get from a table in the database.
In the form on mobilepage1 I have a dropdown list with all department names:
I get this list from my controller like so:
$departmentlist = Company::find($usercompanyid)->departments;
This is how I display the list in the mobilepage1 form:
{{ Form::label('department', 'Department:')}}
<?php
foreach($afdelingslijst as $item) {
$afdelingsarray[$item->afdelingen] = $item->afdelingen;
}
?>
{{Form::select('size',$afdelingsarray)}}
On the second page I want to make a back button.
I tried the jQuery mobile way with a link with: data-rel="back"
But this does not work. I get a page error, it's missing the departmentlist used in mobilepage1. I can make a link to a route to mobilepage1, but I think all the information the user entered in mobilepage1 would be gone.
I see this url in the address bar when I am on mobilepage2 (this is after I filled in the form on mobilepage1 and clicked next).
/public/mobilepage2?size=Personeelszaken&size=32&directechef=Tineke&size=1&size=1&size=1&date-2=&size=1&time=&omschrijving=
Is there a way I can link to the the mobilepage1 route and still keep the information the user entered?
It looks like it would work just by hitting the back button if you passed in the department list with a view composer rather than through a route. Remove it from your route and place this in a file that's being autoloaded...
View::composer('mobilepage2', function($view)
{
$departmentlist = Company::find($usercompanyid)->departments()->lists('afdelingen','afdelingen');
$view->with('departmentlist', $departmentlist);
});
I'm not sure how you are finding $usercompanyid but you should be able to find it within the closure or pass it in by adding use ($usercompanyid) right after the function($view) part.
Also using the lists() function like that will build your array for you so you don't need to worry about the foreach loop in your view.
Since the values are getting passed back and forth as get variables, I think if you use Form::model() instead of Form::open(), it should place all those values back into the input fields for you.
What is the relation between page id and data-url attribute. Is there any relation. Is it fine to change the data-url attribute.
My issue is that there is a page to which i pass the params using changePage. I also specify the data-url in changePage. After going to that page, if i manually refresh the page a new page is added since the data-url is different for that page. That is, the data-url becomes same as the page id. Hope that am clear on this. What should i do so that the page is replaced during manual refresh of page.
And, can someone please explain how JQM uses page id and data-url. Thanks in advance.
The data-url attribute is used to track the origin of the page element. If it is not explicitly set, the pages embedded within the main application document all have their data-url attribute equal to the page id. The only exception to this is the first-page in the document. When you're requesting a page, then jQuery Mobile firstly tries to locate a page with a matching data-url in DOM. If it does not find a such page then it performs an Ajax request and loads the new page in DOM.
You can solve the issue using one of the below 3 ways:
Use the below code to remove the second page from DOM when you're moving to another page.
$(document).on('pagehide', '#second-page', function(event, ui){
$(event.target).remove();
});
This way when you're moving to the first page, the second page will be removed from DOM and your issue will be solved.
OR:
Use:
$.mobile.changePage('car-details.html', {
data: {
id: this.id
}
});
without using the dataUrl setting.
This creates a URL: ../car-details.html?id=my_val
On refresh the URL remains the same so you can still get the parameters and the data-url is the same as the page id.
OR
Before changePage() check whether a page with data-url equal to the second page's id exists in DOM and remove it manually.
if ($("#second-page-id").length > 0 && $("#second-page-id").attr("data-url") === 'second-page-id' ) {
console.log('remove from DOM');
$("#second-page-id").remove();
}
MVS 2010 MVC 3:
I have a Submit page that has severial checkboxes that are been built dynamically as soon as the page load. The user can check one or more checkbox before submitting the form. On the right hand side of the page, there is somewhat a summary of all the previous selections that the user chose. The summary is available from the Submit page and will carry to the other pages. There is an "Add Comment" button at the very top of the page. When the user click it, a popup window with a textbox will display allowing the user to type a comment. How do I display this comment on the page without having a refresh the page?
The main reason for not wanting to do a refresh is because the user could have selected one or more checkboxes, they will lose their states as soon as the page is refreshed.
I tried parent.document.getElementById('DivCommentResult').html(data); - It displayed this message "Microsoft JScript runtime error: Unable to get value of the property 'html': object is null or undefined"
If I understand well, you have to bind the change of your check box to a function that submit a synchone ajax request that obtain the summary you need and replace target content with the result data of your request.
Is it what you want ?
I had to get the parent doucment and retrieve the div id from it.
Once I have it in hand, I set its innerHTML text to the data that I want to display.
var parentDocument = parent.document;
var el = parentDocument.getElementById('commentResult');
Once I have this, I simpley call el.innerHTML = data;
This link helped me to perform autocompleter in struts2. Through this tag i could
A> Show list form database
B> Insert value in database which were not in list
All worked fined..
But, now i have to use struts2-jquery plugin to show that page containing *dojo tag* in a pop-up window. On doing so, the pop up window just appears, and the page is redirected to the form's action. This problem was solved when i removed the dojo tag-sx from the head of that page.
Now the pop up is shown, but i can't insert value which are not in my list. i.e i can't perform the second option mentioned(B)
I've checked this showcase, but struts2-jquery autocompleter tag also couldn't fulfill my second option(B) as it adds an _widget in it's name field
How can i fulfill both option in my case? Thanks in advance
If you mean submit any value that was not originally in the autocompleter list then <sj:autocompleter> tag has forceValidOption attribute for that. See this issue for more information http://code.google.com/p/struts2-jquery/issues/detail?id=587.
I'm using ASP.NET MVC 2 for the first time on a project at work and am feeling like a bit of a noob.
I have a page with a customer search control/partial view. The control is a textbox and a button. You enter a customer id into the textbox and hit search. The page then "refreshes" and shows the customer details on the same page. In other words, the customer details appear below the customer search control.
This is so that if the customer isn't the right one, the user can search again without hitting back in the browser. Or, perhaps they mistyped the customer id and need to try again.
I want the URL to look like this:
/Customer/Search/1
Obviously, this follows the default route in the project.
Now, if I type the URL above directly into my browser, it works fine. However, when I then use the search control on that page to search for say customer 2, the page refreshes with the correct customer details but the URL does not change! It stays as
/Customer/Search/1
When I want it to be
/Customer/Search/2
How can I get it to change to the correct URL?
I am only using the default route in Global.asax.
My Search method looks like this:
<AcceptVerbs(HttpVerbs.Get)> _
Function Search(ByVal id As String) As ActionResult
Dim customer As Customer = New CustomerRepository().GetById(id)
Return View("SearchResult", customer)
End Function
A good place to start might be NerdDinner if you havn't already.
In the mean time though The approach I'd use is to have a page that has my search box on it.
Then I'd have a <div> that I name "SearchResults". This will ultimately hold my results to the search.
I then have a PartialView which takes a model that has all the search results and renders them.
So when I click the button I do a call out to a jQuery action that takes the search parameter, performs the search and then returns my PartialView as rendered HTML.
Back in the client side I take that rendered HTML and replace the contents of my div with the HTML.
The keywords to google, or SO, are RenderPartial. This is back end code to render a partial view and give you html.
Also jQuery postbacks so that you can call an action in your controller.
use RedirectToRoute action result
link