I started learning asp.net (I think the webpages not webforms, razor thingy? :) )
Ok I'm a complete noob, but anyway, I've been looking online and I've seen this question asked multiple times but none of the answers are helping me. I'm following a tutorial and I'm trying to do what its saying but when I run the code.cshtml it just displays the code in a webpage... I know there's gotta be some setting I have to fix or something but I don't know where that is.
my question is, how do I get a web browser to display an x.cshtml file? (I'm using microsoft visual web developer, but I also tried it using notepad and uploading the file to my website, still no good)
I forgot to add, using visual web developer gives me the following errors and wont run:
Error 1 Keyword, identifier, or string expected after verbatim specifier: #
Error 2 A namespace cannot directly contain members such as fields or methods
Error 3 Identifier expected line 8
heres the code
#
{
var total = 0;
var totalMessage = "";
if(IsPost) {
// Retrieve the numbers that the user entered.
var num1 = Request["text1"];
var num2 = Request["text2"];
// Convert the entered strings into integers numbers and add.
total = num1.AsInt() + num2.AsInt();
totalMessage = "Total = " + total;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Add Numbers</title>
<meta charset="utf-8" />
<style type="text/css">
body {background-color: beige; font-family: Verdana, Arial;
margin: 50px; }
form {padding: 10px; border-style: solid; width: 250px;}
</style>
</head>
<body>
<p>Enter two whole numbers and then click <strong>Add</strong>.</p>
<form action="" method="post">
<p><label for="text1">First Number:</label>
<input type="text" name="text1" />
</p>
<p><label for="text2">Second Number:</label>
<input type="text" name="text2" />
</p>
<p><input type="submit" value="Add" /></p>
</form>
<p>#totalMessage</p>
</body>
</html>
I think you are dealing with WebPages, Not MVC. The simplest way to develope webpages is to have WebMatrix.
Check out this tutorial to get started with WebMatrix
When it comes to your code, I only see one mistake i.e, #{ they should some side by side. Other than that everything is working good.
To run your cshtml in browser, please refer to the link I shared at top, that is clearly showing how to run the page in browser.
I think your immediate problem is that you cannot have a linebreak after the '#' character in razor. Try #{ then linebreak...
Related
I know this topic is already uploaded but I don't think it's fully answered The name 'isPost' does not exist in the current context (ASP.NET with Razor)
So, I am trying to add a map to my ASP.NET MVC web page and I am using this documentation - Displaying Maps in an ASP.NET Web Pages (Razor) Site. I don't know if it's only me but when it gets to reading & understanding documentation I kinda suck.
I am using a temp .cshtml file to try and make it work but right now I am stuck and don't really know how to move forward.
here is the code:
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Map an Address</title>
<script src="~/Scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
</head>
<body>
<h1>Map an Address</h1>
<form method="post">
<fieldset>
<div>
<label for="address">Address:</label>
<input style="width: 300px" type="text" name="address" value="#Request["address"]" />
<input type="submit" value="Map It!" />
</div>
</fieldset>
</form>
#if (IsPost)
{
#Maps.GetGoogleHtml(Request.Form["address"],
width: "400",
height: "400")
}
</body>
</html>
Right now I have two main problems:
The name 'Request' does not exist in the current context
The name 'IsPost' does not exist in the current context
The name 'Maps' does not exist in the current context
How do I define them so that I can display the map properly?
I am working on automating an area of a web page (not able to provide the webpage as the contents are confidential, although will try to give as much insight as possible).
This element has on it an html code preview that will change after some selections are done. Here is the page html of the element:
<div _ngcontent-hje-c241="" class="field" style="position: relative;">
<pre _ngcontent-hje-c241="" class="code-pre">
"
<!doctype html>
<html>
<head>
<meta charset='utf'>
<title></title>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' />
<style type='text/css'>body,html, #video {height:100%;margin:0;overflow:hidden;background-color:#000;}</style>
<script type='text/javascript'>
window.onload = function(event) {
var config = {containerID: 'video', Player: true, wmode: 'direct'};
myplayer = new Test.embed('WmAl', config);
}
</script>
</head>
<body>
<div id='video'></div>
</body>
</html>"
(I have edited and removed any confidentials parts of the string for the html, the html itself was not changed.)
I would need to get the value of the element I found through class="code-pre".
Here is what I have tried:
IWebElement htmlTest = driver.FindElement(By.ClassName("code-pre"));
var defaultHtmlTestValue = htmlTest.GetAttribute("value");
Assert.IsFalse(htmlTest.Equals(defaultHtmlTestValue), "The html has not changed after the Http selection");
The assert passes, altho, i would like to see what is the value that is being taken, as i feel like is not taking the html example i am trying to get.
I have also used Debug.Writeline(htmlTest) to see if it worked, but i got "Internal error in the expression evaluator". This is also an issue i will be trying to fix.
I am quite new to automation and stack overflow. Please let me know if there is a way i can improve this post.
I haven't worked with the html previews but looks like the whole html code is just the inner text of an element with class code-pre.
try doing :
String htmlTest = driver.FindElement(By.ClassName("code-pre")).getTex();
System.out.println(htmlTest);
Assert.assertTrue(htmlTest.Equals(defaultHtmlTestValue), "The html has not changed after the Http selection");
You can easily convert above java code into your language.
I've deployed a Wopi client as mentioned in the documentation and now i'm trying to deploy a wopi host, but i'm new to .net enviroment and i don't know how to get the file hosted in wopi-docs folder. (It seems to be encrypted but i don't know how to get the files in that folder)
I have done the next steps:
I implemented an office online server according the official documentation. (Wopi client)
I tried the discovery URL and it worked perfectly.
I deployed a wopi host according to this repo. (Wopi host and a great repo by the way)
Cloned the repo in the server.
I removed Cobalt project from solution from command line in the root directory.
I rebuilt the solution from command line in the root directory.
I ran WopiHost project from command line in the WopiHost directory.
I ran WopiHost.Web project from command line in the WopiHost.Web directory.
I tried Wopi integration with a wopi host page (i don't know if it's correct, but at least it seems to work partially) like this:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<!-- Enable IE Standards mode -->
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<link rel="shortcut icon" href="https://my-server-url.com/wv/resources/1033/FavIcon_Word.ico" />
<style type="text/css">
body {
margin: 0;
padding: 0;
overflow: hidden;
-ms-content-zooming: none;
}
#office_frame {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: 0;
border: none;
display: block;
}
</style>
</head>
<body>
<form id="office_form" name="office_form" target="office_frame" action="https://my-server-url.com/wv/wordviewerframe.aspx?ui=es-mx&rs=es-mx&dchat=1&showpagestats=1&IsLicensedUser=1&WOPISrc=http%3A%2F%2Fmy-server-url.com%3A5000%2Fwopi%2Ffiles%2Ftest.docx" method="post">
<input name="access_token" value="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxMjM0NSIsInVuaXF1ZV9uYW1lIjoiQW5vbnltb3VzIiwiZW1haWwiOiJhbm9ueW1vdXNAZG9tYWluLnRsZCIsIlVzZXJQZXJtaXNzaW9ucyI6IlVzZXJDYW5BdHRlbmQsIFVzZXJDYW5QcmVzZW50LCBVc2VyQ2FuUmVuYW1lLCBVc2VyQ2FuV3JpdGUiLCJuYmYiOjE2MTA2MDU5NDgsImV4cCI6MTYxMDYwOTU0OCwiaWF0IjoxNjEwNjA1OTQ4fQ.KbxGcTVOa3yWCGcEHEGv9MRP_NskfViW_vyMTOupRO4" type="hidden" />
<input name="access_token_ttl" value="0" type="hidden" />
</form>
<span id="frameholder"></span>
<script type="text/javascript">
var frameholder = document.getElementById('frameholder');
var office_frame = document.createElement('iframe');
office_frame.name = 'office_frame';
office_frame.id = 'office_frame';
// The title should be set for accessibility
office_frame.title = 'Office Frame';
// This attribute allows true fullscreen mode in slideshow view
// when using PowerPoint's 'view' action.
office_frame.setAttribute('allowfullscreen', 'true');
// The sandbox attribute is needed to allow automatic redirection to the O365 sign-in page in the business user flow
office_frame.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-forms allow-popups allow-top-navigation allow-popups-to-escape-sandbox');
frameholder.appendChild(office_frame);
document.getElementById('office_form').submit();
</script>
</body>
</html>
And the result that i get is the following error:
Does anyone know how to get the correct name of the files to put into the html file above or how do i get the wopi host web?
Thanks in advance.
The file ID in my repo is just base64 encoded. To verify that you're using the correct path, just take the base64 value and pass it to a decoder or write your own utility to decode it.
The ID should be opaque to the WOPI client (Office Online Server) - it accepts it an passess it back to the WOPI host which can undertand it and return the right file.
I recommend putting breakpoints to GetCheckFileInfo and GetFile methods to see if they're being hit correctly and what data they return.
This is a ASP.NET page written in C#. I want to know how to run this code on browser. I don't have visual studio installed on my laptop. But I want to run this on my PC. Can anyone tell me how to do that ?
<% #Page Language="C#" %>
<!-- code section -->
<script runat="server">
private void convertoupper(object sender, EventArgs e)
{
string str = mytext.Value;
changed_text.InnerHtml = str.ToUpper();
}
</script>
<!-- Layout -->
<html>
<head>
<title> Change to Upper Case </title>
</head>
<body>
<h3> Conversion to Upper Case </h3>
<form runat="server">
<input runat="server" id="mytext" type="text" />
<input runat="server" id="button1" type="submit" value="Enter..." OnServerClick="convertoupper"/>
<hr />
<h3> Results: </h3>
<span runat="server" id="changed_text" />
</form>
</body>
</html>
That code won´t run without visual studio since it have code that must be run on the server. The only thing you can do is copy the code between HTML tag and save it to an HTML file. That will run but since you have logic on your server side your upper case wont work.
Nevertheless, you can use some online tool like https://dotnetfiddle.net/
DotNetFiddle. Change project type to 'Nancy'
You can't, you are missing too many things:
-.Net Framework
-IIS
-MetaData (from a base ASP.net project)
-DLL
What you need to understand is that Browsers only run HTML, CSS, and Javascript. The page you are linking have intermedia code that should be converted to those 3 (HTML, CSS, and Javascript) by a server that interprets the C# code.
You can try Fiddle(Nancy), but you would require the missing server code you are referring on that view.
When I load an aspx page to a popwindow using jQuery model using below code.
function OpenExceptions() {
$('#Equipmentdialog').load('Popups/Test1.aspx', function () {
$(this).dialog({
modal: true,
width: 900,
height: 400
});
});
}
I am unable to call any server side method(C# button click) in the Test1.Aspx method, When I call the the server side events, I am getting resource not found exception?
Can someone please explain me what is the reason?
Thanks
Update: this is the error I am getting
I looked at your sample project and the issue you are experiencing is very simple to explain but I am afraid it's not going to be so simple to make it work.
First I'll explain what's causing the exception.
When the dialog loads, it sets its content to whatever output is generated by the Test.aspx page. Since the page generates this HTML when you navigate to it:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title></head>
<body>
<form name="form1" method="post" action="Test.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTI2NTY4ODI3MWRkmRTYlsUe3rVbAI2jDoNeA5EPuo8=" />
</div>
<div>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgKd2MeEBAKM54rGBl+Fr2fdw6uP6072WYTIw/gz9N5E" />
</div>
<div>
<span id="Label1">Label</span>
<br />
<br />
<input type="submit" name="Button1" value="Button" id="Button1" />
</div>
</form>
</body>
</html>
The dialog ends up displaying a form whose action is set to Test.aspx; therefore, when you click on the Button on the dialog, it attempts to post back the form to Test.aspx but it doesn't find it because this page is inside Popups/Test.aspx. Now, in order to "fix it" (I say this in quotes because it's not really going to fix anything), you could change the dialog's HTML by brute force; doing something like this:
function OpenExceptions() {
$('#Equipmentdialog').load('Popups/Test.aspx #form1', function (response, status, xhr) {
response = response.replace('action="Test.aspx"', 'action="Popups/Test.aspx"'); //Make sure the form's action is accurate
$(this).html(response);
$(this).dialog({
modal: true,
width: 900,
height: 400
});
});
}
And now, when you click the Button you will no longer receive a Resource Not Found Exception; however, because this causes a normal post back the dialog will disappear, the button will post back the page and the label you have on the page will display the current date and time.
Again, this all happens because you are doing normal post backs as opposed to Ajax requests. My approach above would work if the Button in the Test.aspx page performs an Ajax request but not the kind you get when you use Update Panels and Script Managers. You won't be able to use those tools because of the way they work internally...
If you are looking to use Ajax in your app, I recommend you look at WCF Web Services in conjunction with JQuery. There are many good tutorials online on the topic.
I hope my answer at least helps you understand why this isn't working for you and why it won't work if you continue to use this approach. There are many hacks that you could apply to make it work, but I can't think of a single one that's going to be easy to maintain and scale going forward. The best approach is to do Ajax properly, using WCF web services (or Page Methods) and JQuery.