I am using Jasny Bootstrap file upload control in my asp.net project.
It looks really good, but im unable to send the attached file to the server (a .ASHX webservice)
My layout code look like this
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="input-append">
<div class="uneditable-input span3"><i class="icon-file fileupload-exists"></i> <span class="fileupload-preview"></span></div><span class="btn btn-file"><span class="fileupload-new">Select file</span><span class="fileupload-exists">Change</span><input type="file" /></span>Remove
</div>
</div>
The HTML contains an <input type="file" />. You need to set the name attribute of the input element. Also make sure that you're using enctype="multipart/form-data" in the form.
<form action="myscript.ashx" method="post" enctype="multipart/form-data">
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="input-append">
<div class="uneditable-input span3"><i class="icon-file fileupload-exists"></i> <span class="fileupload-preview"></span></div>
<span class="btn btn-file"><span class="fileupload-new">Select file</span><span class="fileupload-exists">Change</span><input type="file" name="myupload"/></span>
Remove
</div>
</div>
</form>
Related
I'm currently working on a project for one of my classes and I suddenly received this error when I tried to run it:
Severity Code Description Project File Line Suppression State
Error
CS0411 The type arguments for method 'IModelExpressionProvider.CreateModelExpression<TModel, TValue>(ViewDataDictionary, Expression<Func<TModel, TValue>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly. Proj1BankApp C:\Users\jross.000\source\repos\Proj1BankApp\Views\Home\Index.cshtml 1 Active
Visual Studio Screenshot
It directs me to my Index.cshtml file but nothing else and I don't know how to fix it, so any help would be appreciated.
Index.cshtml:
#model BankAppModel
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body style="height: 50px">
<form id="form1" runat="server">
<h1>#ViewBag.Title</h1>
<div class="row">
<label asp-for="Name" class="control-label col-sm-3">Name: </label>
<input asp-for="Name" class="form-control col-sm-3" />
<span asp-validation-for="#Model.Name" class="text-danger col"></span>
</div>
<div class="row">
<label asp-for="TransactionMonth" class="control-label col-sm-3">Month: </label>
<input asp-for="TransactionMonth" class="form-control col-sm-3" />
<span asp-validation-for="#Model.TransactionMonth" class="text-danger col"></span>
</div>
<div class="row">
<label asp-for="TransactionDay"class="control-label col-sm-3">Day: </label>
<input asp-for="TransactionDay" class="form-control col-sm-3" />
<span asp-validation-for="#Model.TransactionDay" class="text-danger col"></span>
</div>
<div class="row">
<label asp-for="TransactionYear" class="control-label col-sm-3">Year: </label>
<input asp-for="TransactionYear" class="form-control col-sm-3" />
<span asp-validation-for="#Model.TransactionYear" class="text-danger col"></span>
</div>
<div class="row">
<label class="control-label col-sm-3">Balance: </label>
<input class="form-control col-sm-3" name="balance" readonly />
</div>
<div class="row">
<input class="col offset-sm-3 pl-0" type="submit" name="deposit" value="Deposit" asp-for="Deposit" formmethod="post" />
<input class="col offset-sm-3 pl-0" type="submit" name="withdraw" value="Withdraw" asp-for="Withdraw" formmethod="post" />
<input class="btn btn-secondary" asp-action="Index" type="submit" name="clear" value="Clear" formmethod="post" />
</div>
</form>
</body>
</html>
In my case there was a hidden input property was declared, which was not declared in model class, so i removed that hidden input and error was gone,
this happens when you copy paste the code from another form. than you.
This is likely on a line like InputFor(m=> m.Something)
Actual method you're calling has generic arguments, like Method<T>(T arg1, ..) and the compiler attempts to infer them by looking at the types (the class) of the arguments you pass in..
for example: if you call a method with signature Method<T>(T value) as Method("hi") the compiler is smart enough to figure out this is actually Method<string>("hi")
But this doesn't always work, for example if the type of the argument cannt be resovled at compile time.
You likely have to find this call in your cshtml file and either add the type <typehere> manually or you may have a different compile error in your code which prevents the compiler from resolving this type.
Try scrolling down to the bottom of the error list and see if there are any other errors you can resolve. If not, look for the above.
In my MVC project I applied bootstrap classes to the html input controls but it is not working, before that I used html helper #Html.Editorfor but experiencing the same issue. My code:
HTML:
<div class="container">
<div class="row">
<form action="~/EditProfile/PersonalEdit" method="post" enctype="multipart/form-data">
<div class="col-lg-12 col-md-12 col-sm-12 form-group">
<input type="text" id="fname" name="fname" placeholder="First Name" class="form-control" />
</div>
</div>
</form>
</div>
HTML helper:
#Html.EditorFor(model=>model.FirstName,new {#class="form-control"})
How can I apply Bootstrap classes and make it responsive?
double check and make sure you are linking to bootstrap properly.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
View the source of this page and check if bootstrap.css is available on the page. Also check in chrome developer tools network tab for the path to css and js files. I should not be returning 404 error.
Created a custom widget in Sitefinity MVC, with a custom widget designer:
<div class="form-group">
<label for="My Field">My Field</label>
<div class="row">
<div class="col-xs-3">
<input type="text" sf-model="properties.MyField.PropertyValue" class="form-control" id="MyField" />
</div>
</div>
</div>
Defined in both the controller and the model:
public string MyField { get; set; }
When I click edit, the field shows up as expected. I click save, and then hit edit again: value not stored. Does not help to refresh the page, and is not showing up in the widget itself either.
Am I missing a piece? The documentation is a little long-winded and scattered, I've been scouring through it but nothing is jumping out at me.
I see a put request sent in dev tools, but the request payload is empty. Not sure if this is the right request or relevant.
sf-model should be ng-model
<div class="form-group">
<label for="My Field">My Field</label>
<div class="row">
<div class="col-xs-3">
<input type="text" ng-model="properties.MyField.PropertyValue" class="form-control" id="MyField" />
</div>
</div>
</div>
I'm Developing an ASP.NET Core web application & stuck in a problem regarding the Bootstrap dialog modal. I just want to load a partialView into a dialog modal on a button click & have implemented it in the code. But the problem is Dialog modal is not getting appear, instead page gets refreshes with instant dark splash.
It is very strange, because I have implemented modals previously too.
Here is my code in View.cshtml
#{
Layout = "~/Views/Shared/_AdminLayout.cshtml";
ViewData["Title"] = "Create";
}
<div class="content-wrapper">
<section class="content">
<div class="col-md-12">
<div class="box box-success">
<div class="box-header">
<h3 class="box-title">Add Queue</h3>
</div>
<form asp-action="Create">
<div class="box-body">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group col-md-6">
#* ....... *#
</div>
<div class="form-group col-md-6">
#* ...... *#
</div>
<div class="form-group col-md-6">
#* ...... *#
#* ---- button that triggers the modal ---- *#
<button class="btn btn-default btn-sm" data-toggle="modal" data-target="#adHocAdd">Add New</button>
</div>
<div class="form-group col-md-6"></div>
</div>
<div class="box-footer">
<input type="submit" value="Next" class="btn btn-primary" />
<input type="reset" value="Clear" class="btn btn-warning" />
</div>
</form>
</div>
</div>
</section>
</div>
#* ------- modal div ---------- *#
<div id="adHocAdd" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Create a New Menu</h4>
</div>
<div class="modal-body">
#**Load View*#
</div>
<div class="modal-footer">
<button type="button" class="btn btn-warning" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
#section Scripts {
#{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
Any help is welcome.
The problem seems to be due to your button is within the <form> tag. In ASP.NET I also have experienced this problem.
To overcome the problem you can add type="button" inside your <Button> tag & run the code. so your full code for button will be looks like following.
<button type="button" class="btn btn-default btn-sm" data-toggle="modal" data-target="#adHocAdd">Add New</button>
According to my point of view, this problem is due to triggering of form submission on the button click which launches the model.
For further understanding purpose refer here (dotnetfiddle.net).
There are 2 buttons, one with same as in above problem, & other button is with type="button" respectively.
Button without type="button" will appear & get disappear within seconds. But other one will remain as normal.
A button inside a form will always act as submit if nothing is specified. So either you keep the form inside the model body or remove the model from the form and keep it outside of it.
Here the button is not only triggering the Model but is also submitting the form. So before your model appears, you are doing the post.
Here I made a simple webpage to post pictures, text, etc. I also made a simple ajax file to send the text, picture, etc to the database, and retrieve that information to be displayed in the same webpage. Here is the main webpage:
<div class="here" id="here">
#foreach (var photo in db.Query(photos, galleryInfo)){
<div class="com_1 com_3">
<div class="com_4">
<div class="com_44">
<img alt="miniatura" style="margin-top: 0" src="#Href("~/Photo/Thumbnail2", photo.UserId, new { size="small" })" class="thumbnail-border thumb22" />
<div class="n-s">
<b>#photo.Nombre #photo.Apellido</b>
</div>
</div>
<div class="com_5">
#photo.Comment
</div>
</div>
<div class="comcom">
<div class="comcom1">
<form onsubmit="return fofon(this)" id="gog">
<input type="text" style="display: none" name="GroupId" value="#galleryInfo" />
<textarea class="texta"name="comment" placeholder="Write a comment..."></textarea>
<input type="submit" class="g_sub"/>
</form>
</div>
</div>
</div>
}
In case it gets confuse, this shows every post with a "comment section" below each one (we can call them "Commne2"). The ajax will get the text, picture etc, send it to the database, and post it to another file, which will be displayed here... in the #foreach{}.
Obviously, the posts do not "excist", so any javascript that affects that post, will not work, because that element does not exciste in this case.
So my problem is, how can I create an ajax file (javascript file) that affects the Comment2 so that I can comment a post?