I have 2 views, one called PostToPalPal as below and DomainConfirmationView. On the DomainConfirmationView i have a button that is linking to PostToPayPal which then redirects to paypal via a post event. The problem i have is when i click on this button it does not do anything. I have got this working on another page however i only had #model dynamic at the top of the page and the rest was HTML. Does anyone have idea's where i am going wrong? Apologies if this is something really dumb, this is a my first go at MVC.
Thanks
#model application.Models.PayPal
#{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
<script src="#Url.Content("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"></script>
</head>
<body>
<form id="frm" action=#ViewBag.actionURL>
#Html.HiddenFor(model => model.cmd)
#Html.HiddenFor(model => model.business)
#Html.HiddenFor(model => model.no_shipping)
#Html.HiddenFor(model => model.#return)
#Html.HiddenFor(model => model.cancel_return)
#Html.HiddenFor(model => model.notify_url)
#Html.HiddenFor(model => model.currency_code)
#Html.HiddenFor(model => model.item_name)
#Html.HiddenFor(model => model.amount)
</form>
<p style="text-align: center">
<h4>
<img src="../../Images/New-LogoPNG.png" />
<br />
You are now being redirected to Paypal...</h4>
</p>
</body>
</html>
<script type="text/javascript" language="javascript">
$(this.document).ready(function () {
var frm = $("form");
frm.submit();
});
</script>
DomainConfirmationView
#model Application.Models.DomainCustomerDetails
#using (Html.BeginForm("PostToPayPal", "Home"))
{
<input type ="hidden" name="item" value= ".com"/>
<input type = "hidden" name="amount" value="10" />
}
#{
ViewBag.Title = "Domain order placed";
}
#{
String Input = "Hi" +".<BR /><BR />"
+ "You have a new domain order that has been placed."
+ "<BR /><BR />"
+ "Domain Details"
+ "<BR /><BR />"
+ "Domain name:" + Model.DomainName
+ "<BR /><BR />"
+ "Domain duration " + Model.DomainDuration
+ "<BR /><BR />"
+ "Domain order type" + Model.OrderType
+ "<BR /><BR />"
+ "<BR /><BR />"
+ Model.FirstName
+ "<BR /><BR />"
+ Model.LastName
+ "<BR /><BR />"
+ Model.BusinessName
+ "<BR /><BR />"
+ Model.Address
+ "<BR /><BR />"
+ Model.Address2
+ "<BR /><BR />"
+ Model.PostalCode
+ "<BR /><BR />"
+ Model.EmailAddress
+ "<BR /><BR />"
+ Model.ContactNumber
+ "<BR /><BR />"
+ "<BR /><BR />"
+ "Kind regards"
+ "<BR /><BR />"
+ "xxx"
+ "<BR /><BR />"
+ "Email: support#xxx.com"
+ "<BR /><BR />";
String Output = Server.HtmlDecode(Input);
WebMail.SmtpServer = "mail.xxx.com";
WebMail.SmtpPort = 25;
WebMail.EnableSsl = false;
WebMail.UserName = "xxx#xxx.com";
WebMail.Password = "xxxx";
WebMail.From = "xx#xxx.com";
WebMail.Send("xxx#xx.com", "You have a new domain order " + Model.DomainName,Output);
}
#{
String Inputorder = "Hi " + Model.FirstName
+ "<BR /><BR />"
+ "We are pleased to say your domain name " + Model.DomainName + "has been ordered."
+ "<BR /><BR />"
+ "Domain Details"
+ "<BR /><BR />"
+ Model.DomainName
+ "<BR /><BR />"
+ "Domain duration" + Model.DomainDuration
+ "<BR /><BR />"
+ "What to do next"
+ "<BR /><BR />"
+ "Server IP"
+ "<BR /><BR />"
+"Name Server 1:"
+ "<BR /><BR />"
+"Name Server 2:"
+ "<BR /><BR />"
+"MX:"
+ "<BR /><BR />"
+"A:"
+ "<BR /><BR />"
+"CNAME:"
+ "<BR /><BR />"
+ "PLEASE NOTE"
+ "<BR /><BR />"
+ "Please allow 24 hours for any DNS changes to take effect due to DNS caching by your ISP."
+ "<BR /><BR />"
+ "Many thanks for your order"
+ "<BR /><BR />"
+ "Kind regards"
+ "<BR /><BR />"
+ "xxx"
+ "<BR /><BR />"
+ "Email: support#xxx.com"
+ "<BR /><BR />";
String Outputorder = Server.HtmlDecode(Inputorder);
WebMail.SmtpServer = "mail.xxx.com";
WebMail.SmtpPort = 25;
WebMail.EnableSsl = false;
WebMail.UserName = "xxx#xx.com";
WebMail.Password = "xxx";
WebMail.From = "sales#xx.com";
WebMail.Send( Model.EmailAddress, "Your new domain order: " + Model.DomainName,Outputorder);
}
<p>Thank you, almost done</p>
<p>Please click the purchase button to continue</p>
<input type ="submit" name="btsubmit" value= "Purchase"/>
I also have a controller called DomainsController
[HttpPost]
public ActionResult PostToPayPal(string item, string amount)
{
YippeeYay.Models.PayPal paypal = new Models.PayPal();
paypal.cmd = "_xclick";
paypal.business = ConfigurationManager.AppSettings["BusinessAccountKey"];
bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["UseSandbox"]);
if (useSandbox)
ViewBag.actionURL = "https://www.sandbox.paypal.com/cgi-big/webscr";
else
ViewBag.actionURL = "https://www.paypal.com/cgi-bin/webscr";
paypal.cancel_return = System.Configuration.ConfigurationManager.AppSettings["CancelURL"];
paypal.#return = ConfigurationManager.AppSettings["ReturnURL"];
paypal.notify_url = ConfigurationManager.AppSettings["NotifyURL"];
paypal.currency_code = ConfigurationManager.AppSettings["CurrencyCode"];
paypal.item_name = item;
paypal.amount = amount;
return View(paypal);
}
This section:
#using(Html.BeginForm("PostToPayPal", "Home"))
{
// Form goes in here
}
... is what's writing your tags, which need to contain your submit button. At the moment your submit button is outside this section, so the only things in your form are your two hidden fields. Move your submit button inside the form and it should work.
Related
I try to use the template string, in ASP.NET MVC.
something with the function below, but I can get the vb. can not recognize that template string. someone knows, if I need to do something to configuration on VB.NET / ASP.NET MVC, thank you
var fila;
for (var i = 0; i < data.length; i++) {
fila = data[i];
contenido += "<tr>";
contenido += "<td>" + fila.IIDTIPOUSUARIO + "</td >";
contenido += "<td>" + fila.NOMBRE + "</td>";
contenido += "<td>" + fila.DESCRIPCION + "</td>";
contenido += `
<td>
<button class ='btn btn-primary glyphicon glyphicon-edit'></button>
<button class ='btn btn-danger glyphicon glyphicon-trash'></button>
</td
`;
contenido += "</tr>";
}
I am beginner to jquery-ajax. I trying to get Employee data into front-end using ajax method. But the url is not calling the action method. Please check the below code
MyScripts.js:
function fn_test()
{
var eno = $("#t1").val();
$.ajax({
cache :false,
url: "Home/GetEmpData/"+eno,
type: 'GET',
data:"",
contentType:'application/json;',
success: function (response)
{
var str = "Ename :" + response.EmpName + "<br >";
str += "Job :" + response.Job + "<br >";
tr += "Salary :" + response.Salary + "<br >";
str += "Deptno :"+response.DeptNo+"<br >";
$("#sp1").html(str);
}
});
}
Action method in HomeController.cs
public ActionResult GetEmpData(int id)
{
Employee obj = db.Employees.Find(id);
return Json(obj, JsonRequestBehavior.AllowGet);
}
Index.cshtml
Enter your name :
<input type="text" id="t1" /><br /><br />
<input type="button" id="b1" onclick="fn_test()" value="get message" /><br /><br />
<span id="sp1"></span>
Please help me.
Construct you urls correctly using
url: '#Url.Action("GetEmpData", "Home")',
and pas the data using
data: { id: eno },
and remove
contentType:'application/json;',
Edit
Since your script is in a separate file, modify your html to
<input type="button" id="b1" data-url="#Url.Action("GetEmpData", "Home")" value="get message" />
Then change the script to
$('#b1').click(function() {
$.ajax({
cache :false,
url: $(this).data('url'),
type: 'GET',
data: { id: $("#t1").val() },
success: function (response) {
...
}
});
});
you are passing parameter as query string .you have tell the browser this using ? sign before variable name that you had used in controller and after this you can assign value to this.
function fn_test()
{
var eno = $("#t1").val();
$.ajax({
cache :false,
url: "Home/GetEmpData?parameterNameInController="+eno,
type: 'GET',
data:"",
contentType:'application/json;',
success: function (response)
{
var str = "Ename :" + response.EmpName + "<br >";
str += "Job :" + response.Job + "<br >";
tr += "Salary :" + response.Salary + "<br >";
str += "Deptno :"+response.DeptNo+"<br >";
$("#sp1").html(str);
}
});
}
public ActionResult GetEmpData(int id)
{
Employee obj ;
try{
obj = db.Employees.Find(id);
return Json(obj, JsonRequestBehavior.AllowGet);
}catch(Exception ex)
{ obj=new Employee();
//return empty object
return Json(obj, JsonRequestBehavior.AllowGet);
}
}
In 0.11.2 inputs in <accordion-heading> were possible like so:
<input type="text" value="Will open / close containing group on click" />
<input type="text" ng-click="$event.stopPropagation()" value="Will do nothing" />
In 0.12.0 a click into the second input seems to trigger navigation to the root page (.../#/path -> .../): http://plnkr.co/pyjENpDew621TLTb3Uom
Further investigation shows that the breaking change is make header links keyboard accessible
How do I correctly prevent elements to toggle the accordion in the new version?
Ugly Hack: I ran into the same issue and ended up overriding accordion-group.html template to remove the "href" attribute.
(function () {
'use strict';
function templateOverrides($templateCache) {
var accordionGroupTemplate =
'<div class=\"panel panel-default\">' +
' <div class=\"panel-heading\">' +
' <h4 class=\"panel-title\">' +
' <a class=\"accordion-toggle\" ng-click=\"toggleOpen()\" accordion-transclude=\"heading\"><span ng-class="{\'text-muted\': isDisabled}">{{heading}}</span></a>' +
' </h4>' +
' </div>' +
' <div class=\"panel-collapse\" collapse=\"!isOpen\">' +
' <div class=\"panel-body\" ng-transclude></div>' +
' </div>' +
'</div>';
$templateCache.put('template/accordion/accordion-group.html', accordionGroupTemplate);
}
angular
.module('app')
.run(['$templateCache', templateOverrides]);
})();
I am creating a simple web-based course scheduler for a department in our college and am currently developing the UI. I am creating it with jQuery UI's accordion and sortable extensions. I have it set so that you can add/delete courses and add/delete terms where the terms are all connected sortable ordered lists.
The problem I am running into is when a term is already part of the html page, everything works flawlessly. However, when you add a term OL with jQuery, courses can be added but not removed. When you try to remove the course, you get the Object Expected error. Even if you drag existing li elements from another term, you still get the Object Expected error when you try to remove them from the new term.
My thoughts are 1) I need to refresh the new term or 2) I am not initializing the new term correctly. Below is my javascript.
I can share the html code if requested, but it is just a form with buttons that call the javascript functions.
// Remove selected courses from term
function remCourse(term) {
var termDiv = '#term' + term + 'classes';
$(termDiv).children().children().children(":checked").each(function() {
$(this).parent().parent().remove();
});
}
// Add course to term
function addCourse(term) {
var termDiv = '#term' + term + 'classes';
var course = $(termDiv).children().length + 1;
$(termDiv).append('<li class="ui-state-active"><span class="courseAction"><input name="' + term + 'c' + course + 'box" type="checkbox" /> Dept & Num: <input type="text" id="' + term + 'c' + course + 'num" name="' + term + 'c' + course + 'num" size="8" maxlength="6" /> Credits: <input type="text" id="' + term + 'c' + course + 'cred" name="' + term + 'c' + course + 'cred" size="4" maxlength="3" /> # of Meetings: <input type="text" id="' + term + 'c' + course + 'meet" name="' + term + 'c' + course + 'meet" size="8" maxlength="6" /> Title: <input type="text" id="' + term + 'c' + course + 'num" name="' + term + 'c' + course + 'num" size="20" maxlength="50" /> </span></li>'
);
}
// Remove selected terms
function remTerm() {
$("#terms").children().children().children(":checked").each(function() {
$(this).parent().parent().remove();
});
}
// Add new term
function addTerm(term) {
var termDiv = '#term' + term + 'classes';
$("#terms").append('<div id="term' + term + '" class="connectedTerms"> <h4 class="ui-widget-header"><input class="tbox" name="t' + term + 'box" type="checkbox" />Term ' + term + '<input id="addCourse' + term + '" type="button" onclick="addCourse(this.id.substring(9))" value="Add Course" class="ui-button-text-only" /> <input id="remCourse' + term + '" type="button" onclick="removeCourse(this.id.substring(9))" value="Remove Selected Courses" class="ui-button-text-only" /> </h4> <ol id="term' + term + 'classes" class="connectedSortable"> <li class="ui-state-active"><span class="courseAction"> <input name="' + term + 'c1box" type="checkbox" /> Dept & Num: <input type="text" id="' + term + 'c1num" name="' + term + 'c1num" size="8" maxlength="6" /> Credits: <input type="text" id="' + term + 'c1cred" name="' + term + 'c1cred" size="4" maxlength="3" /> # of Meetings: <input type="text" id="' + term + 'c1meet" name="' + term + 'c1meet" size="8" maxlength="6" /> Title: <input type="text" id="' + term + 'c1num" name="' + term + 'c1num" size="20" maxlength="50" /> </span></li> </ol> </div>'
);
$(termDiv).sortable({
connectWith: ".connectedSortable",
dropOnEmpty: true,
placeholder: "ui-state-highlight"
}).disableSelection();
// I tried doing a refresh below, but it just gave me an error
// so I commented it out.
//$(termDiv).sortable('refresh');
}
I figured out it was a simple typo on my part. In the addTerm() javascript code, I had the the Remove Selected Courses button call the removeTerm() function instead of the remTerm() function. sigh Will I ever stop making typos?
The corrected code is:
// Add new term
function addTerm(term) {
var termDiv = '#term' + term + 'classes';
$("#terms").append('<div id="term' + term + '" class="connectedTerms"> <h4 class="ui-widget-header"><input class="tbox" name="t' + term + 'box" type="checkbox" />Term ' + term + '<input id="addCourse' + term + '" type="button" onclick="addCourse(this.id.substring(9))" value="Add Course" class="ui-button-text-only" /> <input id="remCourse' + term + '" type="button" onclick="remCourse(this.id.substring(9))" value="Remove Selected Courses" class="ui-button-text-only" /> </h4> <ol id="term' + term + 'classes" class="connectedSortable"> <li class="ui-state-active"><span class="courseAction"> <input name="' + term + 'c1box" type="checkbox" /> Dept & Num: <input type="text" id="' + term + 'c1num" name="' + term + 'c1num" size="8" maxlength="6" /> Credits: <input type="text" id="' + term + 'c1cred" name="' + term + 'c1cred" size="4" maxlength="3" /> # of Meetings: <input type="text" id="' + term + 'c1meet" name="' + term + 'c1meet" size="8" maxlength="6" /> Title: <input type="text" id="' + term + 'c1num" name="' + term + 'c1num" size="20" maxlength="50" /> </span></li> </ol> </div>'
);
$(termDiv).sortable({
connectWith: ".connectedSortable",
dropOnEmpty: true,
placeholder: "ui-state-highlight"
}).disableSelection();
}
I'm using JQuery Mobile 1.2.0 version.
I want to put some html code in this context:
<div id="div-primeros" data-role="collapsible" data-theme="a" data-content-theme="c" data-collapsed="false">
<h2>Primeros</h2>
[I WANT TO ADD CODE DYNAMICALLY HERE]
</div>
And the code I want to add is:
<div class="ui-grid-a">
<div class="ui-block-a" style="width:93%">
<ul data-role="listview" style="width:100%">
<li id="4" data-icon="false">
<a href="index.html">
<img src="some.jpg"></img>
<h3>some text</h3>
<span class="ui-li-count">some text</span>
</a>
</li>
</ul>
</div>
<div class="ui-grid-b" style="width:7%">
<input cant="1" type="number" value="0" min="0" max="8" style="width:100%">
</div>
</div>
So I tried doing this using this code ("primero" is a JSON variable):
$("#div-primeros").append(
"<div id=\"" + i + "\" data-role=\"listview\" class=\"ui-grid-a\">" +
"<div class=\"ui-block-a\" style=\"width:95%\">" +
"<ul style=\"width:100%\">" +
"<li id=\"" + primero.id + "\" data-icon=\"false\">" +
"<a href=\"menu_detalle.html\">" +
"<img src=\"" + primero.thumb + "\"></img>" +
"<h3>" + primero.nombre + "</h3>" +
"<p>" + primero.descripcion + "</p>" +
"<span class=\"ui-li-count\">" + primero.precio + "</span>" +
"</a>" +
"</li>" +
"</ul>" +
"</div>" +
"<div class=\"ui-grid-b\" style=\"width:5%\">" +
"<input cant=\"" + primero.id + "\" type=\"number\" value=\"0\" min=\"0\" max=\"8\" style=\"width:100%\">" +
"</div>" +
"</div>");
The result is that the content not formatted correctly, and this content is out of collapsible "div-primeros".
What am I doing wrong??? I've tried with:
$("div-primeros").trigger("create");
and
$("div-primeros").page();
with no successful results.
Anyone knows how can I refresh all the code?
Thank you so much!!!
Bye
Don't break it up in multiple lines, use single quotes in place of the double quotes surrounding the html you want to append. Like so:
$('#div-primeros').append('<div class="ui-grid-a"><div class="ui-block-a" style="width:93%"><ul data-role="listview" style="width:100%"><li id="4" data-icon="false"><img src="some.jpg"></img><h3>some text</h3><span class="ui-li-count">some text</span></li></ul></div><div class="ui-grid-b" style="width:7%"><input cant="1" type="number" value="0" min="0" max="8" style="width:100%"></div></div>');
Here's a fiddle. http://jsfiddle.net/wU6pr/