How to add a new webpage to ASP.NET MVC - javascript

Right now I am making a MVC that has a default page that loads up. From this page, the user can press a button to go to the next page. So far, I have made the first page work and a button that goes to a specified URL for the second page. The only issue I am having is making the view that I want to correspond to the second page have the correct URL.
Here is the code for my button link to the next URL
<input type="button" value="Create" onclick="location.href='#Url.Action("IndexA", "HomeController")'" />
I guess my question is how do I make my view have the specified URL that I want so it can be accessed?

I used something like this in my own project.
#if (Request.UrlReferrer != null && Request.UrlReferrer.Host == Request.Url.Host)
{
<a href="#Request.UrlReferrer" class="dbtn btn-11">
<i class="fa fa-undo"></i>
#Resources._Action_Back
</a>
}
only came from within the domain that was published I said let the button appear.
there is something like add controller in default settings controller name + controller. So just write the name there.

I had to put "home" in the URL.Action instead of "HomeController"

Please see this photo.
https://ibb.co/4SS5nYh
You add a new controller and a new view for that new page (also a model). I have called mine Test.
Then in the button. you call them with url action.
<input type="button" value="Create" onclick="location.href='#Url.Action("Index", "Test")'" />

Related

Removing a Product using button in laravel route link

I created a sample products page using laravel framework,where I added a Remove button to remove that particular product onclick. below is the laravel route code added to the button
<button onclick= "window.location= '{{ route('customer.wishlist.remove', $item->id) }}'" > Remove </button>
here the item id is automatically generated from database which can also be seen by inspecting the remove button code.
on clicking the Remove button the product is getting removed. but when i run the route link separately in the browser then also the product getting removed because the same location link is given to button also.
I want this operation work only on Remove button click. if i entered the route url directly it should'nt. How can i resist that.
please help me on this
thank you
First of all you're using get method so it can be directly accessible to the browser.
Now if you don't want to allow a user to directly access that URL then you need to make the request as POST
<button onclick="event.preventDefault(); document.getElementById('delete').submit();">Remove </button >
<form id="delete" action="{{ route('customer.wishlist.remove', $item->id) }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
Make your route as post

Django; How can I connect javascript to db?

I'm doing project using Django and now I am trying to adapt js into the project. I'm not familiar with js and I'm wondering how I can manipulate db using js. For example, I want to use js for creating delete function. Currently, when I push delete button, I jump into the other page and then I have to push delete button again. But what I want to do is push the delete button and then pop up the window to confirm and delete something. How can I adapt js into Django in general?
Here is current way
first I have to push the button and jump into another page
<button style="display: inline;" onclick="window.location='{% url 'blog:delete_entry' entry_id=entry.id %}'" class="btn btn-link">Delete</button>
and then I have to push a button on the other page again.
<button type="submit" class="btn btn-outline-danger" id="delete-button">Delete</button>
Here is views.py
def delete_entry(request, entry_id):
entry = Entry.objects.get(id=entry_id)
if request.method != 'POST':
form = EditEntryForm(instance=entry)
else:
form = EditEntryForm(instance=entry)
entry.delete()
return HttpResponseRedirect(reverse_lazy ('blog:my_entry'))
return render(request, 'blog/delete_entry.html', {'entry': entry, 'form': form})
Anyone who can give me tips?
I could be wrong, but I typically only use javascript for the front-end. You are doing the back-end in Python with the Django frame work... it would be foolish not to use Python to manipulate the DB. Here is a template for mysql although I used Flask...
https://github.com/rootVIII/flask_mysql_template/blob/master/template.py
Even though it's Flask and not Django, the idea is still the same.
Your button should (or any form button) should have a Django endpoint associated with it (basically a path to the Django function). That way when the button is pressed, the Django/Python code on the back-end is ran. There you can perform your logic and database business in the Python code on the back-end.
Sorry for the Flask examples... but here is an endpoint for Flask in the index.html file from the above link... notice how the form action is associated with an endpoint /login_register
/login_register is what is ran when the form input button is pressed. It is a function on the back-end... in your case it might be named delete_entry
<form action = /login_register method="POST" id="userform">
<fieldset>
<!-- some labels and input values here -->
<input type="submit" name="submit" value="login/register" id="submit"/><br>
</fieldset>
</form>
So basically what I'm saying is that your button should not call Javascript. It should call a Python function on the back-end. And no you do not need to make a whole rest API to do this as was mentioned above

AngularJS - Showing a popup dialog using a service

Here is what I am trying to achieve: I have a topnav with a login button. When the login button is clicked, I want to display my login popup dialog.
Similarly, certain pages will have a giant "Register" button. I want the login popup to also appear when that button is clicked.
In order for both the topnav and other (outside) components to display the login popup, it was recommend that I create service for my login popup (See my previous question: (Separate controller from directive?)
My question is: Can someone please outline the steps I need to take in order to create this service? I'm having a bit of trouble, even after reading the documentation.
Here's what I have so far:
angular.module('myApp')
.factory('login', LoginService);
function LoginService() {
return {
showLoginPopup: function () {
// Need to show my login popup here
}
}
}
Is this correct so far? Where do I define my HTML for the login popup? Do I use the templateUrl attribute? Is there another recommended approach?
Thanks
Edit
For sake of example, let's assume my template is something very simple
<div class="login-popup">
<input type="text" id="Username" />
<input type="text" id="Password" />
<button>Submit</button>
</div>
I assume I'll need an ng-show attribute. What should this be linked to? Typically, I link it to a property of a controller... But since is initiated by a service, there is no controller object to it. What am I missing?

How to make a contact's phone number clickable to call and to send a message in ionic?

I cloned the ionic project from GitHub
While the contact's phone number is not clickable to call and message. So for the index.html file line 39, I converted from
<p ng-if="contact.emails.length > 0">{{contact.emails[0].type}} : {{contact.emails[0].value}}</p>
to
<p ng-if="contact.phones.length > 0">{{contact.phones[0].type}} : <a ng-href='{{contact.phones[0].value}}'>{{contact.phones[0].value}}</a></p>
But it turns out the app will not load any contact's information anymore.
Is there anything I missed or am I totally wrong on sending data?
to make phone call with ionic you need to add this code in confi.xml
<access launch-external="yes" origin="tel:*" />
and in your view you need to add:
<a ng-href=tel:{{user.phoneNumber}} class="button button-positive">Call me</a>
Update:
I've just noticed it's (probably) an issue with loading data not the link itself. Would need to see your controller code to know more about why it's not populating the ng-href if it's not the issue below...
Previously:
Using the following href should be enough to trigger a call:
tel:' + number
Angular (which ionic sits on) doesn't like anything unusual going into an anchors href unless you tell it you want it to. See here:
http://forum.ionicframework.com/t/ng-href-tel-redirecting-to-call-with-empty-number/4567/2
The quickest fix, if you 'just' want it to work is this in your view:
<p ng-if="contact.phones.length > 0">{{contact.phones[0].type}} : {{contact.phones[0].value}}</p>
and then in your controller:
$scope.triggerCall = function(number){
document.location.href = 'tel:' + number
}

how to show/hide the single element when coming from different pages?

I have 2 pages name "A" & "B", both pages have a link which will open the same page "X".
But page "X" will show/hide some components as per from which page its coming.
On page "X", I want to show/hide my buttons on page named "X".
If I come from "Page A" > they should be visible.
And If I come from "Page B" > they should not be visible.
==========================================
I am taking approach for doing this is by passing variable/value in URL on page A and B.
HTML code page A:-
<a data-fancybox-type="iframe" class="various marginLeft10 button" href="/Provision/Summary/MC-IT0401-ATUTEJA?abc">View Summary</a>
HTML code page B:-
<a class="marginLeft50 button" href="/Provision/Summary/MC-IT0401-ATUTEJA?xyz">Confirm & Proceed</a>
Page X Code=
<div class="marginTop50 marginBottom valignBottom" role="button" id="summaryButtons">
<input type="button" class="active" value="Back" id="stepSummaryBack">
<input type="button" class="bigButton marginLeft50" value="Ready for Diagnostic" id="stepSummaryConfirm">
</div>
This Particular Div should show/hide as per navigation from page "A" or "B".
I am not sure now how to confirm the URL along with the variables (?abc and ?xyz) I am passing in the "href" using jquery.
Please suggest.
And let me know if anything is not clear or need more details.
So in the onload event could you just do.
var URL = window.document.URL.toString();
var vars = URL.split("?");
then your variable should be vars[1];
I would suggest handling the show/hide decision while rendering Page X, not with javascript once it has already loaded. You don't need to use query params in your url (?abc and ?xyz). Access the HTTP_REFERER from the Page X request in your controller to see whether the request came from /page_a or /page_b, then use that information while rendering Page X to determine whether or not to include the buttons.

Categories