I tried to development my first MVC module in DNN8 these days.
It is a very simple demo. A button and textbox in the view. What I want is click the button to call an action in the controller and got the return string from the action, then show it in the textbox.
Here is the action code:
public ActionResult test1()
{
return Content("Return something");
}
Here is the script:
$(document).ready(function () {
$("#btnSub").click(function () {
// his.action);
$.ajax({
type:"GET",
contentType:"application/text",
url: "@Url.Action("test1", "Sky")",
data:"",
dataType: "text",
success: function (data) { $("#txtResult").val(data); alert("Success!") },
error:function(){alert("Failed!")}
});
});
});
And here is the result:
<!DOCTYPE html>
<html lang="en-US">
<head id="Head">
<!--*********************************************-->
<!-- DNN Platform - http://www.dnnsoftware.com -->
<!-- Copyright (c) 2002-2015, by DNN Corporation -->
<!--*********************************************-->
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /><title>
My Website > SkyMVCPage
</title><meta id="MetaKeywords" name="KEYWORDS" content=",DotNetNuke,DNN" /><meta id="MetaGenerator" name="GENERATOR" content="DotNetNuke " /><meta id="MetaRobots" name="ROBOTS" content="INDEX, FOLLOW" /><link href="/Resources/Shared/stylesheets/dnndefault/7.0.0/default.css?cdv=81" type="text/css" rel="stylesheet"/><link href="/Portals/_default/admin.css?cdv=81" type="text/css" rel="stylesheet"/><link href="/DesktopModules/MVC/SkyDnnMvcModule/module.css?cdv=81" type="text/css" rel="stylesheet"/><link href="/Resources/Search/SearchSkinObjectPreview.css?cdv=81" type="text/css" rel="stylesheet"/><link href="/Portals/_default/Skins/Xcillion/bootstrap/css/bootstrap.min.css?cdv=81" type="text/css" rel="stylesheet"/><link href="/admin/ControlPanel/ControlBar.css?cdv=81" type="text/css" rel="stylesheet"/><link href="/Portals/_default/Skins/_default/WebControlSkin/Default/ComboBox.DnnBlack.css?cdv=81" type="text/css" rel="stylesheet"/><link href="/Resources/Shared/components/DropDownList/dnn.DropDownList.css?cdv=81" type="text/css" rel="stylesheet"/><link href="/Resources/Shared/scripts/jquery/dnn.jScrollBar.css?cdv=81" type="text/css" rel="stylesheet"/><link href="/Resources/Shared/Components/FileUpload/dnn.FileUpload.css?cdv=81" type="text/css" rel="stylesheet"/><link href="/Portals/_default/Skins/Xcillion/css/jquery.smartmenus.bootstrap.css?cdv=81" type="text/css" rel="stylesheet"/><link href="/Portals/_default/Skins/Xcillion/Menus/MainMenu/MainMenu.css?cdv=81" type="text/css" rel="stylesheet"/><link href="/Portals/_default/Skins/Xcillion/skin.css?cdv=81" type="text/css" rel="stylesheet"/><link href="/Portals/0/portal.css?cdv=81" type="text/css" rel="stylesheet"/><script src="/Resources/libraries/jQuery/01_09_01/jquery.js?cdv=81" type="text/javascript"></script><script src="/Resources/libraries/jQuery-UI/01_11_03/jquery-ui.js?cdv=81" type="text/javascript"></script><meta name="viewport" content="width=device-width,initial-scale=1" /></head>
<body id="Body">
Lots of html information, I'm not full past it here.
I have tried lots of ways to fix it, for example, set the Ajax to return JSON, but failed
Anyone know how to fix it?
Thanks
Sky