With the MVC3 Razor synax, one may render a string like so
#ViewData("photo")
My problem is: How can I append a dot to the above code.
The following will result in a "Public member 'jpg' on type 'String' not found.":
#ViewData("photo").jpg
I've tried the following code but does not produce my intended result:
#ViewData("photo") .jpg
#ViewData("photo"):.jpg
#ViewData("photo") & ".jpg"
Thanx for advance for your help.
And please dont advice me to append the "jpg" in the controller's code like so:
ViewData("photo") = "filename.jpg"
I've searched the Net for the same problem but found none, not even something
similar.
By the way, I'm using VB.net.
How about this?
#(ViewData("photo")).jpg
Edit: And with the dynamic ViewBag:
#(ViewBag.photo).jpg
Adding as answer:
#(ViewData("photo") + ".jpg")
You could always try:
#string.concat(ViewData("photo"),".jpg")
Related
I'm trying to parse my URL with wildcards. The problem appears when I try to parse long strings with a wildcard. For example, my URL looks like this:
http://testapi.com/v1/cards/%s/reissue?DesignId=%s&Comment=%s
and this is my code:
get_object.setRestUrl(String.format(url, card_id, design_id, comment))
When comment = "Something" it works, but when comment = "Something something", it goes on an error and says that it is "Unable to parse HTTP request".
How is it possible to make suitable my code with long strings with wildcards? I know that when typing long string it gives URL that looks like this:
http://testapi.com/v1/cards/1/Block?reasonId=1&comment=Something%20like%20that%20example
Just needed to modify with comment.replace(" ", "%20"), and now it works fine, even when there are no spaces.
Source : https://forum.katalon.com/t/getting-an-error-unable-to-parse-http-request/17685
P.S
If it is not allowed to post answer from another site, I will remove it.
You could try it:
get_object.setRestUrl(String.format(url, card_id, design_id, comment.replace(" ", "%20")))
More information could be found at https://forum.katalon.com/t/getting-an-error-unable-to-parse-http-request/17685
Test.vbhtml
<span>The time is #DateTime.Now.</span>
#Helper Time()
#<p>The time is #DateTime.Now.</p>
End Helper
Note the full stop (.) at the end of the #DateTime.Now
MVC3 accepts Test.vbhtml. Both the <span> line and the #Helper compile.
MVC4 gets a compilation error in the helper only:
Compiler Error Message: BC30203: Identifier expected.
The <span> in MVC4 works but the #Helper does not.
A solution is easy enough, such as replacing the full stop with .. But why does this happen?
Edited for clarification.
With the dot placed as such the compiler looks for a property or method name. Do like this instead:
#<p>The time is #(DateTime.Now).</p>
If you really want to use # sign then use as shown below. it solves the problem.
razor tries to look for #sign before rendering so it creates problem.
<text>#</text><p>
I have that string ...
C:\Users\ApplicationData\Folder1\Myapp.exe
How could i cut like:
C:\Users\ApplicationData\Folder1
I have tried s.split("\Myapp.exe") , where s is C:\Users\ApplicationData\Folder1\Myapp.exe
Plase help me, thanks.
Use the Path class:
Path.GetDirectoryName("C:\Users\ApplicationData\Folder1\Myapp.exe")
Check it here:
http://msdn.microsoft.com/en-us/library/system.io.path.getdirectoryname.aspx
you can use the System.IO.FileInfo class.
It contains a function FullName, which returns the directory full name.
check this link
I'm using Sahi for Test Automation of web application. I have to write a script for sahi for uploading a file. But unfortunately I don't know the way. Can anybody please help me?
File upload can be a complex thing depending upon any validations you do on the upload. For a starter, you can try out the following:
Synatx:
_setFile(element, filePath [, actionURL])
eg:
_setFile(_file("id"), "C:\abc\efg.jpg", "formSubmit.jsp");
If there are javascript validations on the file field, you can try this hack. Before submitting the file, change the field’s type to “text”, and then set its value. Eg.
// set the file
_setFile(_file("file"), "scripts/demo/uploadme.txt");
// Change the "type" attribute of file field
if (_isIE()){
_call(_file("file").outerHTML = _file("file").outerHTML.replace(/type=['"]?file['"]?/, "type=text"));
}else{
_call(_file("file").type = "text");
}
// Set the value into the textbox
_setValue(_textbox("file"), "scripts/demo/uploadme.txt");
This works for most of the cases. If you still get any error, you can post it here.
Thanks,
Vivek
You can use the following
_setFile(_file("id"), "C:\\abc\\efg.jpg");
Not sure if you need anything more complex?
Note that as of Sahi 4.3, there is a _setFile2 function that automatically handles js validations and does this input type conversion.
I've solved using the function setFile2, with internally changes the type of field to text
I can get $esc.html to work, but not $esc.url, it just comes up literal even though I follow example at: http://velocity.apache.org/tools/devel/generic/EscapeTool.html
Interestingly enough, on that page the url() section's head is "$attrib.name" instead of url().
Any ideas?
Thanks.
Worked for me in Tools 2.0. Maybe you have old version?
$esc.url("bread & butter") = bread+%26+butter