HTML
<h3>Single Upload</h3>
<form method="post" enctype="multipart/form-data">
File <input type="file" name="file" />
<br />
<input type="button" value="Upload" onclick="return SaveExit()" />
</form>
<img src="C:/Users/Gigabyte/source/repos/ReimbursementSystem/ReimbursementSystemAPI/wwwroot/Images/biomimikrifix1.png" width="100" height="200" alt="3" />
I want to simply show the image from the other project with the path but it doesn't work. is there a way to simply show it from another project?
In ASP.Net Core MVC you are not allowed to load local resource file rather than wwwroot/images folder by default. But if you want to use a different location then you can simply add this middleware to your startup.cs
Startup.cs
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(#"C:\Users\Gigabyte\source\repos\ReimbursementSystem\ReimbursementSystemAPI\wwwroot", "images")),
RequestPath = "/images"
});
cshtml
<img src="/Images/biomimikrifix1.png" width="100" height="200" alt="3"/>
Hope this will solve your issue.
You can use this code
<img src="/Images/biomimikrifix1.png" width="100" height="200" alt="3" class="detailImage" />
Related
I want to upload <img> tag src in my spring mvc. I have already tried to upload img using input file method. But is it possible to upload a img src to spring controller?
<form method="POST" action="<c:url value='/upload' />"
enctype="multipart/form-data">
Please select a file to upload : <input type="file" name="file" />
<input type="submit" value="upload" />
</form>
I have already uploaded the image using file input tag.
<form method="POST" action="<c:url value='/upload' />"
enctype="multipart/form-data">
Please select a file to upload : <img src="demo.png" />
<input type="submit" value="upload" />
</form>
Is it possible to do the upload using img tag without using file input tag.
You need to insert your data to form to be able to submit the data to a database or other uses.
Since <img src="demo.png" /> is just a static html code, form canĀ“t get the data from that.
What you can do is to pass the src to <input type="file" name="file" />
I am running into this error while using Url.Action is ASP.net MVC 5
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Home/AddPhoto
Here is the relevant portion of the view. The following url.action call is the one that fails : #Url.Action("AddPhoto", "Home")
</div>
#using (Html.BeginForm("Index", "Home", FormMethod.Post, new { #class = "form-horizontal", role = "form" }))
{
<div class="col-md-8">
<textarea class="search-query span2 text-center" rows="13" style="width: 2200px; height: 50px;" id="searchText" name="searchText" placeholder="What is on your mind?" type="text" value="What is on your mind? "></textarea>
<br />
<a href="#" id="addphoto" onclick="window.location.href='#Url.Action("AddPhoto", "Home")'">
<span rel="tooltip" title="Add photo"><i class="fa fa-camera"></i></span>
</a>
<br />
<input type="reset" value="Cancel" name="Command" style="text-align:right" /> <input type="submit" name="Command" value="Post" style="text-align:right" />
<br />
<br />
In my HomeController.cs file, I do have this method:
public ActionResult AddPhoto()
{
return View();
}
And the actual view file , does exist under Views/Home
Screen grab of views/home directory
I am hence not understanding the reason why I am hitting the 404 not found error. Can someone please help me out over here?
AddPhoto action in your case must be [HttpPost]. It should be [HttpGet]. Remove [HttpPost]. Only GET works from browser location bar.
Here we go:
Try this:
<a href="#" id="addphoto" onclick="window.location.href='../Home/AddPhoto'">
or
<a href="~/Home/AddPhoto" id="addphoto">`
Hope it helps;)
I have an ASP.NET 5 app. I'm creating this app as a learning exercise on a Mac. Currently, I'm trying to use the validation tag helper. In my view, I have the following code:
<form method="POST" action="~/account/login">
<h1>Login</h1>
<div class="validation" asp-validation-summary="All" />
#Html.ValidationSummary(false, "", new { })
<input id="Username" name="Username" />
<br />
<input id="Password" name="Password" />
<br />
<button type="submit">Login</button>
#Html.AntiForgeryToken()
</form>
The traditional #Html.ValidationSummary(...) approach works. However, the <div class="validation" asp-validation-summary="All" /> approach does not. I want to break away from using the tradition #Html. approach and use tag helpers as much as possible.
Why won't the validation results appear in the asp-validation-summary?
Thank you!
Since this commit
the ValidationSummaryTagHelper takes a value of the ValidationSummary enum instead of a string
So you need to write:
<div class="validation" asp-validation-summary="ValidationSummary.All" />
See also in the sample on Github.
I have a html control like
<input id="Button1" type="button" value="button" />
<input id="Text1" type="text" />
<img alt="" src="" id="img1" />
i want to set its tooltip or tittle in codebehind .
I tried the following code but its not working
Button1.Attributes["tittle"] = "i am button";
Text1.Attributes["tittle"] = "i am text";
img1.Attributes["tittle"] = "i am image";
this is not working please help
Set runat="server" for each control:
<input id="Button1" runat="server" type="button" value="button" />
Then in CodeBehind in Page_Load use this:
Button1.Attributes.Add("title", "i am button");
You need to mark those elements as runat="server" so that the server knows about them. Otherwise, server-side code won't be aware that they exist.
Alternatively, you could add a blob of javascript to the response message body and have the JS set the attributes. That's silly and ugly, though.
Can any one pf you please tell me how to clear the File upload control value using javascript.
function ClearFileUpload()
{
var fil = document.getElementById("FileUpload1");
fil.select();
n=fil.createTextRange();
n.execCommand('delete');
fil.focus();
}
Due to security reasons there is no direct access to the value of a file upload control on the client using javascript.
What you could to is deleting the element out of the dom and recreating it. Have a look at this
link for an example
<div id="uploadFile_div">
<input type="file" id="uploadFile" onkeydown="return false;" size="40" name="uploadFile"/>
</div>
<a onclick="clearFileInputField('uploadFile_div')" href="javascript:noAction();">Clear</a>
<script>
function clearFileInputField(tagId)
{
document.getElementById(tagId).innerHTML = document.getElementById(tagId).innerHTML;
}
</script>
working code tested IE,Firefox
<% using (Html.BeginForm("SaveSignatory", "LabMaster", FormMethod.Post, new { enctype = "multipart/form-data", id = "Signatory" }))
{ %>
<div>
</div>
<div id="divUpload">
<input type="file" name="filUpload" accept="image/*" id="filUpload" onchange="showimagepreview(this)" />
</div>
<img id="imgprvw" alt="uploaded image preview" height="200" width="200" />
<input type="button" id="btnRemoveUpload" value="Remove Upload Image" onclick="clearFileInputField('divUpload')" />
<input type="button" onclick="saveData()" />
<%}%>
function clearFileInputField(tagId) {
document.getElementById(tagId).innerHTML =
document.getElementById(tagId).innerHTML;
}