I'm setting up my first ever ASP.NET MVC server and teaching myself how to use it for a particular project I'm working on.
I have a couple of controller "endpoints" set up and working wonderfully for HTTP POST requests but, as a "tangential" part of this project, I would like to have the controller serve up a page with a file upload form.
Specifically, I'd really like to use the Vue File Agent, preferably implemented using the CDN distribution method because I'd rather not install additional components on the server for this one little thing if I can get away with it.
I'm not new to ASP.NET, HTML, or CSS (and even limited JavaScript), but I am unfamiliar with using ASP.NET MVC controllers and views to serve page(s). As stated, I've figured out how to use the controllers to handle the POST requests I'm generating from other systems.
Also, I have a "basic" understanding of how the view works and I've got the controller serving up an HTML file. However, when I try to include the Vue File Agent component via the CDN, I'm not getting anything.
I've tried a variety of different Vue File Agent samples just to get something on the page, including the Gmail Inspired Demo on CodePen, but I must be missing something because I can't get the actual "sample" to show up and it seems to be totally ignoring all of the CSS styling.
In my controller, I have this:
Function Index() As ActionResult
Return View()
End Function
And my Index.vbhtml file looks like this:
#Code
Layout = Nothing
End Code
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Insurance Submission Form</title>
<link rel="stylesheet" href="https://unpkg.com/vue-file-agent#latest/dist/vue-file-agent.css" />
<script src="https://unpkg.com/vue-file-agent#latest/dist/vue-file-agent.umd.js"></script>
<style>
.vfa-demo {
position: relative;
}
.vfa-demo .file-preview-wrapper::before {
background: transparent;
}
.vfa-demo .file-row {
position: relative;
z-index: 15;
line-height: 24px;
text-align: left;
background: #EEE;
margin-bottom: 5px;
padding: 2px 5px;
}
.vfa-demo .remove {
float: right;
margin-top: -3px;
}
.vfa-demo .progress {
float: right;
width: 85px;
height: 10px;
margin-top: 7px;
margin-right: 10px;
background: #FFF;
border: 1px solid #AAA;
}
.vfa-demo .progress.completed {
display: none;
}
.vfa-demo .drop-help-text {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: 2px;
background: rgba(255, 255, 255, 0.75);
z-index: 1200;
font-size: 32px;
font-weight: bold;
color: #888;
align-items: center;
justify-content: center;
display: none;
}
.vfa-demo .is-drag-over .drop-help-text {
display: flex;
}
.vfa-demo .upload-block {
border: 2px dashed transparent;
padding: 20px;
padding-top: 0;
}
.vfa-demo .is-drag-over.upload-block {
border-color: #AAA;
}
.vfa-demo .vue-file-agent {
border: 0 !important;
box-shadow: none !important;
}
</style>
</head>
<body>
<script type="text/x-template" id="vue-file-agent-demo">
<div class="vfa-demo bg-light pt-3">
<VueFileAgent class="upload-block"
ref="vfaDemoRef"
:uploadUrl="'https://www.mocky.io/v2/5d4fb20b3000005c111099e3'"
:uploadHeaders="{}"
:multiple="true"
:deletable="true"
:theme="'list'"
:maxSize="'25MB'"
:errorText="{
size: 'This file is too large to be attached',
}"
v-model="fileRecords">
<template v-slot:before-outer>
<p>Email Attachment example with drag & drop support and <span class="badge">attachment</span> keyword basic detection.</p>
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Name" value="John Doe">
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Email address" value="johndoe#example.com">
</div>
<div class="form-group">
<textarea v-model="message" class="form-control" placeholder="Your Message"></textarea>
</div>
</template>
<template v-slot:file-preview="slotProps">
<div :key="slotProps.index" class="grid-box-item file-row">
<button type="button" class="close remove" aria-label="Remove" v-on:click="removeFileRecord(slotProps.fileRecord)">
<span aria-hidden="true">×</span>
</button>
<div class="progress" :class="{'completed': slotProps.fileRecord.progress() == 100}">
<div class="progress-bar" role="progressbar" :style="{width: slotProps.fileRecord.progress() + '%'}"></div>
</div>
<strong>{{ slotProps.fileRecord.name() }}</strong> <span class="text-muted">({{ slotProps.fileRecord.size() }})</span>
</div>
</template>
<template v-slot:file-preview-new>
<div class="text-left my-3" key="new">
Select files or drag & drop here
</div>
</template>
<!-- <template v-slot:after-inner>
<div class="text-left pt-1">
Select files or drag & drop here
</div>
</template > -->
<template v-slot:after-outer>
<div title="after-outer">
<div class="drop-help-text">
<p>Drop here</p>
</div>
<button type="button" class="btn btn-primary" v-on:click="send()">Send</button>
</div>
</template>
</VueFileAgent>
</div>
</script>
<!-- ----------------------------- -->
<div class="container py-3">
<div id="app">
<h5><a target="_blank" href="https://safrazik.github.io/vue-file-agent">Vue File Agent</a> Playground</h5>
<hr>
<ul class="nav nav-pills mb-2">
<li class="nav-item">
<a target="_blank" class="nav-link" href="https://codepen.io/safrazik/pen/BaBVNEE">1. Preloading Exising Demo</a>
</li>
<li class="nav-item">
<a target="_blank" class="nav-link" href="https://codepen.io/safrazik/pen/BaBpYme">2. Profile Picture Demo</a>
</li>
<li class="nav-item">
<a target="_blank" class="nav-link active" href="https://codepen.io/safrazik/pen/OJLgvya">3. Gmail Inspired Demo</a>
</li>
</ul>
<hr>
<vue-file-agent-demo></vue-file-agent-demo>
</div>
</div>
<script type="text/javascript">
var component = {
data: function () {
return {
fileRecords: [],
message: 'I am sending you the attachments',
}
},
methods: {
removeFileRecord: function (fileRecord) {
return this.$refs.vfaDemoRef.removeFileRecord(fileRecord);
},
send: function () {
if (this.message.indexOf('attachment') !== -1 && this.fileRecords.length < 1) {
if (!confirm('You have mentioned about attachments in your message. Are you sure to send without attachments?')) {
return;
}
}
alert('Message sent!');
}
}
}
component.template = '#vue-file-agent-demo';
Vue.component('vue-file-agent-demo', component);
new Vue({
el: '#app'
});
</script>
</body>
</html>
I tried using various other different upload "templates" I've found with varying degrees of success, but I feel I'm still failing to understand some key concepts of working with ASP.NET MVC controllers and views.
For one thing, in the <template v-slot:file-preview="slotProps"> and <template v-slot:after-outer> blocks of the code above, the CodePen has the <button> elements defined with #click="somefunctionname()".
However, when I publish these, the server returns an error indicating that 'click' is not declared (IntelliSense also reports the same error in the Visual Studio IDE). I found some other examples using Vue that showed what appears to be the same basic functionality written as v-on:click="somefunctionname()", so I tried that (as I have listed above), but I'm still getting nothing.
I'm obviously not understanding how the syntax should be working here, and I'm sure it's "simply" a matter of finding the right documentation, but I'd really like to understand the ASP.NET MVC view a little better and figure this out, not only because I want to get this "pretty" upload working, but because I really want to get a better handle on how to use this technology.
What is it that I'm doing wrong and how can I get this functionality working on my ASP.NET MVC controller? How do I define these # directives in an ASP.NET MVC view without causing the compiler to freak out (I had the same issue with some of these # directives in a CSS <style> block, so it's clearly something I'm going to need to deal with)?
EDIT
So, as I sorta mentioned above, I've been testing by publishing the site to my web server and viewing the site via the public DNS name. Just to see if I would get anything different, I tried running the site from the Visual Studio debugger.
Interestingly, when I did this, the IDE broke with an exception in my _Layout.vbhtml:
#Scripts.Render("~/bundles/jquery")
#Scripts.Render("~/bundles/bootstrap")
#RenderSection("scripts", required:=False)
Looking at my site's directory structure, there is no ~\bundles\ directory. Digging around a little, I found all of the jQuery and Bootstrap files located in the ~\Scripts\ directory, so I simply removed the two calls to the #Scripts.Render() method (leaving the call to #RenderSection()) and tried again. This time, I didn't get the exception, so I went ahead and published again to test. Unfortunately, I got the same results as what I posted in my screenshot, so that doesn't appear to be the source of my "issue", but I thought I'd mention it here, just in case it helps to point me in the right direction.
As I said at the beginning of my question, this is my first time setting up an ASP.NET MVC server, so I've not done much in the way of customization or modification to the base template from Visual Studio apart from creating a new controller and associated view and adding a couple of things to the web.config / global.asax to handle some of the other functionality I'm implementing. Perhaps there's something I should have done, but I don't really know where to start.
Well, I finally figured out at least part of my problem, and it's because I'm a moron. I stumbled across it when I opened up my browser's "Developer Tools" and drilled down through a few screens. Apparently, I was missing a pretty important piece of the Vue puzzle in my HTML. Once I added this line to my <head> (the "core" Vue library):
<script src="https://cdn.jsdelivr.net/npm/vue#2.6.12/dist/vue.js"></script>
I finally got a visible upload box. It's still missing all the nice-looking styling, but at least the control is there now and I can start working with it a little more.
I am trying to use flex box with bootstrap columns so that all the columns are always horizontally centered. The markup mentioned below works fine for firefox, chrome and Android but fails on iOS and safari. I haven't tested IE yet.
HTML:
<!-- The fourth column falls down -->
<div class='row row-1 text-center'>
<div class="col-xs-3 red">Hi</div>
<div class="col-xs-3 blue">Hi</div>
<div class="col-xs-3 blue">Hi</div>
<div class="col-xs-3 blue">Hi</div>
</div>
<!-- Works Fine and centers the columns -->
<div class='row text-center'>
<div class="col-xs-3 red">Hi</div>
<div class="col-xs-3 blue">Hi</div>
<div class="col-xs-3 blue">Hi</div>
</div>
CSS:
.row {
display: flex;
display: -webkit-flex;
flex-wrap:wrap;
-webkit-flex-wrap: wrap;
-webkit-justify-content: center;
justify-content: center;
}
div[class^=col-] {
float: none;
display: inline-block;
vertical-align: top;
}
On Chrome, Firefox and Android
On Safari and iOS
JSFIDDLE
Is there anything that I should be adding to the columns so that they appear in one line.
It's pseudo-element in the .row causing the problem.
This happens because Safari browser treats :before and :after
pseudo-elements as if they were real elements.
Try
.row:before, .row:after{
display: none;
}
or better create a class say, .flex-row and do this
<div class="row flex-row">
{{contents here..}}
</div>
.flex-row{
display: flex;
display: -webkit-flex;
flex-wrap:wrap;
-webkit-flex-wrap: wrap;
-webkit-justify-content: center;
justify-content: center;
}
.flex-row:before, .flex-row:after{
display: none;
}
FIDDLE
If anyone is still lost for a solution, I had an issue where my columns were TALL in Safari:
To solve this, I simply added this CSS selector (I know !important isn't best practice, but I tried several solutions and eventually landed on this):
.d-flex {
display: block !important;
}
Now, my columns looks like this, which is how it originally looked in Chrome, Firefox, etc.:
I am using Materializecss for my website and I'd like to display tooltips on the smaller action buttons whenever the user presses the big action button. Materializecss shows tooltips only on hover by default.
Is there a way to change this?
Thank you
<li> <!-- Small button -->
<a class="btn-floating green tooltipped" data-position="left" data-delay="50" data-tooltip="Add friends">
<i class="material-icons">add</i>
</a>
</li>
Check out this github issue
Github user philipraets created a nice codepen to demonstrate his soluton.
Edit (For the Lazy):
philipraets created a simple css style:
.mobile-fab-tip {
position: fixed;
right: 85px;
padding:0px 0.5rem;
text-align: right;
background-color: #323232;
border-radius: 2px;
color: #FFF;
width:auto;
}
then wrapped the tooltip within another link element using that style:
<div class="fixed-action-btn click-to-toggle" style="bottom:24px; right:24px;">
<a class="btn-floating btn-large red"><i class="large material-icons">settings</i></a>
<ul>
<li>
<i class="material-icons">create</i>
Edit <!--tooltip-->
</li>
<li>
<i class="material-icons">event</i>
Save to calendar <!--tooltip-->
</li>
<li>
<i class="material-icons">supervisor_account</i>
Switch responsible <!--tooltip-->
</li>
</ul>
</div>
Creating a jQuery Mobile popup with a header, the default works pretty good (I would like to address that non-round top-left corner some day):
<div data-role="header">
<h1>Useful Header</h1>
</div>
What is the proper way to add a sub-header? By sub-header, I mean text like the header, but smaller, probably with a smallish margin between the header and sub-header.
Google isn't much help, and this naive attempt fails:
<div data-role="header">
<h1>Useful Header</h1>
<h6>Simple Sub-header</h6>
</div>
Here is a way to get the desired layout with CSS:
<div data-role="header">
<h1>Useful Header</h1>
<p class="popup-subheader">Simple Sub-header</p>
</div>
.popup-subheader {
text-align: center;
margin-top: -5px;
margin-bottom: 6px;
font-size: smaller;
font-weight: normal;
}
The images in the webpage below link to their respective pages. Works fine in IE8 & IE9 but not IE7.
In IE7 when you hover over the image the link url is recognised (previews in bottom left corner of browser) but is not clickable?
http://www.signport.co.uk/test/asg_ourwork.php
Can anyone tell me if there's a fix for it?
Thanks :)
This solution is the new solution:
CSS
.item a{
display:block;
overflow:hidden;
height:170px;
-moz-box-shadow:0 0 10px black;
-webkit-box-shadow:0 0 10px black;
-o-box-shadow:0 0 10px black;
-ms-box-shadow:0 0 10px black;
box-shadow:0 0 10px black;
}
You can DELETE the box-shadow SPAN you don't need it. I made it so you only need to add this line of code.
The problem is the hirarquy of the TAGS.
In this example you can see the correction working. In chrome it works exactly like yours. In IE7 the link works like you want, you only need to correct the rollover.
The Problem:
<div style="opacity: 1;" class="item">
<a href="http://www.signport.co.uk/test/asg_ask.php">
<div class="boxshadow">
<p>
<img src="http://www.signport.co.uk/test/Images/thumb_ask.jpg" alt="ASK Italian" height="170" width="300">
</p>
</div>
</a>
</div>
The Solution
HTML
<div style="opacity: 1;" class="item">
<a href="http://www.signport.co.uk/test/asg_ask.php">
<span class="boxshadow"></span>
<img src="http://www.signport.co.uk/test/Images/thumb_ask.jpg" alt="ASK Italian" height="170" width="300">
</a>
</div>
CSS
.projects .item{box-shadow: 0 0 10px 0 black;padding:0;margin:10px;}
.projects a {display: block;height: 150px;margin-bottom: 20px;}
.projects a .boxshadow {position: absolute;z-index: 999999;box-shadow: none;}