Using buttons in MVC3 - asp.net-mvc-3

In my view I am using buttons like this
<button style=" color:White; height:30px; width:100px; background-image: url('#Url.Content("~/Content/Images/RedButton.gif")');" name="button" value="Add" type="submit">Add</button>
<button style=" color:White; height:30px; width:100px; background-image: url('#Url.Content("~/Content/Images/RedButton.gif")');" name="button" value="Save" type="submit">Save</button>
<button style=" color:White; height:30px; width:100px; background-image: url('#Url.Content("~/Content/Images/RedButton.gif")');" name="button" value="Cancel" type="submit">Cancel</button>
and handling them in the controller like this
[HttpPost]
public ActionResult Index(BuildRegionModel model, string button)
{
if (button == "Add")
{
}
if (button == "Save")
{
}
if (button == "Cancel")
{
}
return View(model);
}
Is there a way that I can do something like this
Add
Save
Cancel

Submitting forms should be done with submit buttons. That's the semantically correct way. That's how forms should be submitted according to the HTML specification.
Anchors should not be used for posting and submitting forms. They are used to redirect and issue GET requests. An anchor cannot submit a form. You will have to write javascript and fake a form submission when it is clicked so that all form fields are sent.
Don't do it, I wouldn't recommend it.
For example things like pressing enter while the focus is inside a textfield will no longer work and you will have to write additional javascript to handle this case to which all internet users are accustomed to. It is a nightmare. The way you did it initially with submit buttons is perfect.

Related

Cannot get radio buttons to align with text correctly in pdf

I have an html fragment that looks like this:
<style>
.r {
display: flex;
}
.d-flex {
display: flex;
align-items: center;
}
</style>
<div class="r">
<input type="radio" disabled="disabled" value="1">
<div class="d-flex">
<span class="answernumber">1) </span>
<div class="answer"><p>One</p></div>
</div>
</div>
When I render this in a browser the radio button, the "1)" and the "One" are all aligned nicely. But when I render this html in a pdf the radio button is not aligned with the text. I have tried multiple alternative style definitions for the classes r, d-flex, answernumber and answer and also for the input[type="radio"] and every time it looks good in a browser, the result is no good in the pdf.
Interestingly, check boxes work just fine. Is there a way to get the html to render in the pdf aligned? Or is this something that needs to be fixed inside iText?
The html inside the div.answer may be much more complex and I have no control over it as it is delivered to me by an external system, so I am limited as to what I can do with the html. What I am in control over, is the style definitions and any configurations to be done to iText (perhaps some ConverterProperties).

How to go back on click of a button from the .vue without opening a new window?

I'm trying to create a button that goes back to the login, or redirects to /login, currently I've tried doing it both with el-button and inertia-link, they both work but not how I would like.
This is the code i've already tried to get the inertia-link to work:
<el-button-group style="margin-left: 53%; margin-bottom: 10px">
<inertia-link class="el-button--info" :href="'/login'">
<i class="fas fa-chevron-left"></i>
</inertia-link>
<el-button
:type="getStatus()"
:loading="loading"
#click="submit()">Enviar Link
</el-button>
</el-button-group>
Code with el-button:
<el-button-group style="margin-left: 53%; margin-bottom: 10px">
<el-button
type="info"
icon="fas fa-chevron-left"
#click="redirect()"
>
</el-button>
<el-button
:type="getStatus()"
:loading="loading"
#click="submit()">Enviar Link
</el-button>
</el-button-group>
methods() {
redirect(){
window.open('/login');
}
}
With the inertia-link it's ugly, the class doesn't look right if I just put class="el-button" it works but I need to add a el-button type as info, how I have it right now as class="el-button--info" it doesn't work. With the el-button it opens another tab, I want to stay on the same page, just go to the login page like the inertia-link does.
You can use the visit method from Inertia:
redirect() {
this.$inertia.visit('/login');
}
For some reason it has been lost in the docs, but you can still find it in the history on Github: https://github.com/inertiajs/inertia-vue/tree/2c6da0ccb9b4f80c94650ba687cfad0073f3f0c2#manually-making-visits

css overflow with elements moved outside div, elements disappear

I have a form in a div where I brought submit buttons out of the div to another part of the screen. This works nicely. However, I want to lock that div down to a specific size and relative position and use overflow:auto so when it grows too big (the form has elements that are unhidden with checkboxes) the entire screen doesn't scroll, just the div. The problem is, as soon as I add the overflow style, the submit boxes I moved off the div are hidden. I assume this is because with overflow all elements are locked into that div and scroll bars allow you to access them, but in this case the elements are moved left:-500px and it doesn't even give me a scroll bar to scroll left to see them. Basic code follows:
<div class="div1">
<div class="div2">
<form>
<input type="submit" class="sub1" />
</form>
</div>
</div>`
CSS would be:
div.div1 {
position:relative;
width:1000px;
margin: 0 auto;
}
div.div2 {
width:500px;
height:500px;
position:absolute;
top:125px;
left:500px;
}
input[type=submit].sub1 {
position:absolute;
left: -500px;
}
So this works, but as soon as I change the div2 css to:
div.div2 {
width:500px;
height:500px;
position:absolute;
top:125px;
left:500px;
overflow:auto;
}
The submit button disappears.
My question: is there any way to get the scrollbar and keep the div2 container to 500px high without losing the elements outside the div?
If I understand correctly, you can move div2 within the form and leave the submit button outside of div2. That way, the submit button will always be visible and div2 can have overflow.
<div class="div1">
<form>
<div class="div2">
<!-- form fields go here -->
</div>
<input type="submit" class="sub1" />
</form>
</div>
Note: You'll likely need to adjust styles on the button, but I'm not entirely sure about your end goal.

ActionButton instead of ActionLink

I want to create a button which when clicked calls an action. I have used Html.ActionLink to create a link which does exactly that but there is no Html.ActionButton. Is there some other way?
Here is an example using Bootstrap's CSS button and applying it against the link to make it look exactly like the button.
#Html.ActionLink("Select", "Select", new { id = patient.Id }, new { #class = "btn btn-primary", #style = "color:white" })
Is there some other way?
You could use a html <form>:
#using (Html.BeginForm("someAction", "someController"))
{
<button type="submit">OK</button>
}
This seems very simple - am I missing something?
#Html.ActionLink("About", "About","Home", new { #class = "btn btn-success" })
Use this:
#using (Html.BeginForm("yourAction", "yourController"))
{
<input type="submit" value="Some text"/>
}
#using (Html.BeginForm("ActionName", "ControllerName")){
<input type="button" value="Submit" />
}
a[type="button"] {
background-color: #d3dce0;
border: 1px solid #787878;
cursor: pointer;
font-size: 1.2em;
font-weight: 600;
padding: 7px;
margin-right: 8px;
width: auto;
text-decoration: none;
}
#Html.ActionLink("ActionName", "ControllerName",null, new {type = "button" })
Sometimes your button might have nested markup (e.g. for an icon)
This might be helpful to some people:
<button type="button" onclick="location.href='#Url.Action("Action", "Controller")'" class="btn btn-success">My button name <i class="glyphicon glyphicon-search"></i></button>
type=button is required to prevent page from submitting... Another possible solution (if you think type=button looks weird because the element is already a button) would be to call event.preventDefault() in the OnClick javascript handler.
<button onclick="event.preventDefault(); location.href='#Url.Action("Action", "Controller")'" class="btn btn-success">My button name <i class="glyphicon glyphicon-search"></i></button>
This should answer your question.
Can I use an asp:Button like an Html.ActionLink?
Uses CSS to make the link look like a button.
Or use the button inside the form with the form controls moving the page along.
You can write a link to controller and view this way / skip the whole razor notation (worked for me recently on my localhost!):
<button type="submit">OK</button>
use FORMACTION
<input type="submit" value="Delete" id="delete" formaction="#Url.Action("Delete", new { id = Model.Id })" />
I know this is an old topic, but this helped me:
#Html.ActionLink("New member", "Create", null, new {#class = "btn btn-default"})
Make sure you use the correct overload or else you will be directed to the wrong controller.
you need to use a "null" before the new {} as shown below:
#Html.ActionLink("About", "Action Name","Controller Name",null, new { #class = "btn btn-success" })
Notice the null above. This is important!!!
For those of you trying to make an anchor tag look like a button in Bootstrap v3 (maybe v4, too), beware that there are some subtle styling differences regarding margin that bootstrap targets to the Input element and not the A element. This can be a little frustrating when trying to put several buttons next to each other.
There's a rather obvious reason why MVC doesn't have a ButtonLink helper: Think about it. Buttons do not link to anything. They run code. So what code would the helper render? I mean it seems simple that it could just render something like onclick="window.location=/controller/method..." but, is that really what you want? Is it what everyone always wants? Isn't that really just doing a GET? It gets kind of goofy.
So, really, if you want a button that opens a link the easiest way is to do what everyone else suggested and style an A tag to look like a button but then probably go into your stylesheet and do a very specific target of your button anchors to get the same styling as actual buttons. Or use an Input tag and force Razor (or whatever) to render the link inline with your JavaScript.

Button image for sitecore marketer module

I want to change submit button of Web Forms for Marketers module with image in Sitecore.
Thank in advance
You can change the button by updating contents of the following file:
\sitecore modules\Web\Web Forms for Marketers\Control\SitecoreSimpleFormAscx.ascx
Replace
<wfm:FormSubmit ID="submit" runat="server" Class="scfSubmitButtonBorder"/>
with you own custom control (which can contain Image / LinkButton / whatever)
It sounds like you are trying to change the submit button into an <input type="image" />. I have not found a way to do this with WFFM. You can style the submit button, or you can export the form to ASCX and make the change to an image yourself.
You can do quite a bit with CSS styling of <input type="submit" />.
http://www.456bereastreet.com/lab/styling-form-controls-revisited/submit-button/
You can change the button style in Default.css.
Use background-image to add the image.
Below example use an image as background for the Submit button in WFFM:
.scfSubmitButtonBorder
{
background-image: url(/images/bg_button.png);
padding-left: 5px;
float: right;
margin-bottom: 10px;
}
.scfSubmitButtonBorder input
{
border: none;
padding: 0 5px 0 0;
color: white;
font: 14px/14px FrutigerRoman, Arial !important;
width: 100px;
height: 30px;
background-image: url(/images/bg_button.png);
background-position: right -30px;
background-color: transparent;
cursor: pointer;
}
I suppose you're talking about Web Forms for Marketers module, aren't you? It is not clear from your initial question...
Anyway, in Form designer you can select the submit button and you'll its properties on the left side. Among various properties, the very first is the edit box called "Button Name" . Put the desired text for the Submit button there.
Here's how I did it.
First, create a custom control:
namespace Sitecore.Custom.Controls
{
public class ImageSubmitButton : Sitecore.Form.Web.UI.Controls.SubmitButton
{
public string ImageUrl { get; set; }
protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
{
if (string.IsNullOrEmpty(ImageUrl) == false)
{
writer.AddAttribute("type", "image");
writer.AddAttribute("src", ResolveUrl(ImageUrl));
}
// This won't overwrite our explicit type="image"
base.AddAttributesToRender(writer);
}
}
}
Export the form as ASCX in sitecore, use the Developer Center to create a new Sublayout and copy the exported ASCX code into this file. First, register a new prefix
<%# Register TagPrefix="ctrl" Namespace="Sitecore.Custom.Controls" Assembly="<AssemblyName>" %>
Finally, change
<cc0:submitbutton runat="server" onclientclick="$scw.webform.lastSubmit = this.id;" text="Submit" validationgroup="..." cssclass="..." id="..." onclick="OnClick" >
</cc0:submitbutton>
to
<ctrl:ImageSubmitButton ImageUrl="~/imgs/button.png" runat="server" OnClientClick="$scw.webform.lastSubmit = this.id;"
Text="Submit" validationgroup="..." cssclass="..." id="..."
OnClick="OnClick"></ctrl:ImageSubmitButton>
Finally, replace the form in your item with the sublayout.

Resources