Embed route value parameter in MVC Url Action - asp.net-mvc-2

I am struggling with the MVC syntax for setting up the image src with the below code. I use Webform view engine and following the syntax
<img src="<%: Url.Action("LoadPhoto", "EmployeeProfile",
new { empno = "<%: ViewBag.EmpNo%>"}) %>" />
getting this error Newline in constant
How to embed this ViewBag value as a route parameter for Action?

As you are already in code, the following should work:
<img src="<%: Url.Action("LoadPhoto", "EmployeeProfile",
new { empno = ViewBag.EmpNo }) %>" />
(I'm reasonably sure the newline mentioned in the error isn't the one between "EmployeeProfile", and new { ... }.)

ViewBag is not supported by MVC 2. You should use ViewData instead like this:
<img src="<%: Url.Action("LoadPhoto", "EmployeeProfile",
new { empno = ViewData["EmpNo"] }) %>" />

Related

Blue Dot Menu displaying HTML as text

After the app menu html is retrieved, it is displayed as text instead of html. Chrome complains Resource interpreted as Script but transferred with MIME type text/plain. I'm using MVC on the Force.com platform. I've tried specifying the content type of the response as "text/html" and "application/javascript", but neither worked.
[EDIT 1]
Code
<script>
intuit.ipp.anywhere.setup({
menuProxy: "https://c.na55.visual.force.com/"
+ "apex/bluedot",
grantUrl: "https://c.na55.visual.force.com/"
+ "apex/authpage"
});
</script>
<ipp:bluedot>
<div id="intuitPlatformAppMenu">
<a id="intuitPlatformAppMenuLogo" href="javascript:void(0);" title="Intuit App Center">
<span id="intuitPlatformAppMenuDot"> </span>
</a>
<div id="intuitPlatformAppMenuDropdown" style="display: none;">
<div id="intuitPlatformAppMenuDropdownTop"></div>
<div id="intuitPlatformAppMenuDropdownInner">
<<=======
</div>
</div>
</div>
</ipp:bluedot>
When dropdown is open, code is added at arrow location as string and a class 'open' is addedto #intuitPlatformAppMenuLogo.
Image
[EDIT 2]
Server side apex code
public with sharing class GetBlueDotMenu {
public String response {get; set;}
public GetBlueDotMenu() {
QbApiController api = new QbApiController ('GET', 'QB API' , null, null, 'https://appcenter.intuit.com/api/v1/Account/AppMenu');
response = api.execute();
}
}
api.execute() returns the response body and saves it to response which is then rendered on the page.
This issue arises from Visualforce's default rendering of strings as escaped. To fix it, the apex:outputText attribute escaped needs to be "false". See http://bit.ly/13CSXve
PFB link -
https://developer.intuit.com/docs/0025_quickbooksapi/0060_auth_auth/widgets/blue_dot_menu
For IE8, you should add (as mentioned in the above doc)
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ipp="">
You can clear the browser's cache and try it again.
Plz let me know how it goes.
Thanks

GET/POST variable not set in netbeans IDE

I dunno if its a silly mistake but a post/get variable is not being set, while it is supposed to be. Here are the HTML and php code snippets:
<html>
<head>
<title>
Chain Story
</title>
</head>
<body>
<form method="GET" action="check-valid.php">
<textarea name="a" rows="5" cols="50"></textarea>
<input type="submit" value="Add" />
</form>
</body>
</html>
check-valid.php:
<?php
require 'includes/connect.inc.php';
$conn_ref = connect_db('chainstory') or die(mysqli_error());
if(isset($_GET)){
echo 'Get variable set';
if(isset ($_GET['a'])){
$as = $_GET['a'];
$query = "insert into story1 values (1, " . $as . ")";
mysql_query($query, $conn_ref);
}
else{
echo $_GET;
}}
?>
I get the following output:
Get variable set
Notice: Array to string conversion in /home/kevin/Code/php/myWebsite/check-valid.php on line 15
Array
I am coding this in netbeans. Can anyone point me out what mistake im making? :(
Did you try rename the textarea? Longer name , and give id to textarea same the name.
What browser does you use for testing?
I met some problems with input names in IE for example if an input name matches a javascript function name or protected names. Have you a javascript function or variable in your code what's name is a ? Because if the name of the input conflicts with a js var or name IE does not send the input field to the server. (Chrome Firefox and other browsers does)

java parameter in jsp:include

I wanted to know if I can pass a java variable to a . I tried to do something like this inside a jsp file:
<% String folder = request.getParameter("something"); %>
<jsp:include page="../<%=folder%>/myframe.jsp" ></jsp:include>
This does not work. I get an error which says 'Failed to find resource /=folder/myframe.jsp'.
Can this be done?
Thanks for any help.
You either need to have the page parameter as an entire string or as an entire substitution.
<jsp:include page="<%= myPageToInclude %>" />
<jsp:include page="path/to/my/page.jsp" />
Also when concatenating strings inside a value you need to escape the double quotes.
So for your problem :
<% String folder = request.getParameter("something"); %>
<jsp:include page="<%= \"../\" + folder + \"/myframe.jsp\" %>" />
Should work fine, or for easier reading :
<%
String folder = request.getParameter("something");
String page = "../" + folder + "/myframe.jsp";
%>
<jsp:include page="<%= page %>" />
Concidering your param name as "something",
Try this:
<jsp:include page="../${param.something}/myframe.jsp" />
Other solution is to do that:
<% String folder = request.getParameter("something"); %>
<% pageContext.setAttribute("folder", folder); %>
<jsp:include page="../${folder}/myframe.jsp"></jsp:include>
First is better but both should works.

Insert Image to a MVC Project using jQuery

I want to insert an imege to a MVC Project, i used following code to do that,
but i want to pass that image using jquery instead of pass data using Html.BeginForm.
how can i do it,
<% using (Html.BeginForm("uploadImage", "ItemMaster", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
%>
<p><input type="file" id="fileUpload" name="fileUpload" size="23"/> </p>
<p><input type="submit" value="Upload file" /></p>
<%= Html.Hidden("hdnItemCode", null, new { style = "width:100px" })%>
<%
}
%>
If you're looking for a method to upload a file via jQuery, I suggest this question and answers.

ASP.NET MVC2 +file uploading (HttpPostedFileBase class)

I have problem with uploading my file. I want to upload it from my edit view:
<%
using (Html.BeginForm("edit","profile",FormMethod.Post, new { enctype="multipart/form-data" }))
{%>
<%: Html.ValidationSummary(true) %>
<%: ViewData["ErrorMessage"] %>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.Image) %>
</div>
<div class="editor-field">
<input type="file" id="Image" name="Image" />
<label id="LabelErrorImage" class="errorMessage" />
</div>
<p>
<input type="submit" value="Save" onclick="return Validate(); return false;"/>
</p>
</fieldset>
<% } %>
I want to use HttpPostedFileBase class. My edit action:
[Authorize]
[HttpPost]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(string id, HttpPostedFileBase file, FormCollection formValues)
{
if (ModelState.IsValid)
{
if (file != null && file.ContentLength > 0)
{
CustomHelpers.createFolder();
var tmpPath = MyConfig.UPLOAD_FILE_PATH + "/" + Membership.GetUser().ProviderUserKey.ToString();
var path = Path.Combine(Server.MapPath(MyConfig.UPLOAD_FILE_PATH), "Avatar");
var fileExtension = Path.GetExtension(file.FileName);
file.SaveAs(path);
user.Image = "Avatar";
}
adventureDB.SaveChanges();
return RedirectToAction("Index");
}
}
But I always have empty the file object, why????? Do you have any ideas, suggestions why it can work like that? Maybe there is problem how I pass on the file value to my Edit action?
EDIT:
IT IS REALLY STRANGE AS EVEN WHEN I REMOVE
using (Html.BeginForm("Index","Profile",FormMethod.Get, new { enctype="multipart/form-data" }))
The page source still has:
<body>
<form method="post" action="6111e591-b92d-4bcb-b214-ab8f664b35f9" id="form1">
I mean I can not change the tag but have no idea why :/
Try changing:-
public ActionResult Edit(string id, HttpPostedFileBase file,
FormCollection formValues)
to:-
public ActionResult Edit(string id, HttpPostedFileBase image,
FormCollection formValues)
as the name of your input is image
<input type="file" id="Image" name="Image" />
edit
To be honest something else is stopping the binding of image. Is this the whole form that you have posted?
A few things to test
You have HTTPOST decorating your method twice, although I don't believe this should make a difference.
View the source and make sure there is nothing else named name=image in the source.
Make sure you empty your cache and make sure source is correct before testing again
Try using <form action="/profile/index" method="post" enctype="multipart/form-data">
Judging by your last edit you have a problem with master pages/layout? Is this a mvc/webforms hybrid?
The solution of this problem when:
We use Master.Site,
We want to upload file in a view,
We are sure that it should work but we all the time has null,
Then:
Guys were right - I had wrong name in my view - check it!
Check source code of your view and if you have 2 < form > tags you should remove the < form > tag from Master site as then the second one is ignored!
Now it should work.
Well, in your view you named the file input 'image' but your action method accepts a parameter called 'file'. Rename one of those and it should work.