This example describes the use of Javascriptresult in asp.net mvc. Share to everyone for your reference, specific as follows:
In the page we use JavaScript to set the span label style with ID qubernet, as follows:
Js:
<script>
$ (function () {
var thisobj = document.getElementById ("qubernet");
Thisobj.setattribute ("Style", "Color: #f00; font-size:22px;");
</script>
Html:
<body>
<span id= "qubernet" >qubernet span!!! </span>
</body>
Operation Effect:
The above results can also be achieved using the Javascriptresult in MVC, as follows:
Controller method:
[HttpPost]
Public Javascriptresult Getjavascriptresult ()
{
const string THISJS = "var thisobj = document.getElementById (\" Qubernet\ "); Thisobj.setattribute (" style\ ", \" color: #f00; font-size:22px;\ ");";
Return JavaScript (THISJS);
}
Js:
<script>
$ (function () {
$.ajax ({
type: "Post",
URL: "/qubermanage/syslogin/ Getjavascriptresult "
}
); </script>
Html:
<body>
<span id= "qubernet" >qubernet span!!! </span>
</body>
Note: The AJAX approach to jquery is used here, and of course you need to introduce the jquery library, you know
More interested in asp.net related content readers can view the site topics: "ASP.net optimization skills summary", "asp.net string operation skills Summary", "ASP.net Operation XML Skills summary", "asp.net file Operation skills Summary", "asp.net Ajax Skills Summary topic and the ASP.net caching operation skills Summary.
I hope this article will help you to ASP.net program design.