Skip to content

Instantly share code, notes, and snippets.

Scott Sauber scottsauber

Block or report user

Report or block scottsauber

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View RazorViewToStringRenderer.cs
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Routing;
using System;
View inputField.test.js
import React from "react";
import { render, fireEvent } from "react-testing-library";
import InputField from "./InputField";
import { Formik } from "formik";
test("should have validation error given input field is touched and error exists on form", async () => {
const fieldName = "firstName";
const labelName = "First Name";
const { getByLabelText, findByTestId } = render(
<Formik
View INCORRECT-inputField.test.js
import React from "react";
import { render, fireEvent } from "react-testing-library";
import InputField from "./InputField";
import { Formik } from "formik";
test("should have validation error given input field is touched and error exists on form", () => {
const fieldName = "firstName";
const labelName = "First Name";
const { getByLabelText, getByTestId } = render(
<Formik
View InputField.js
import React from "react";
import { Field } from "formik";
const InputField = props => {
return (
<Field
name={props.fieldName}
render={({ field, form }) => (
<div>
<label htmlFor={props.fieldName}>{props.labelName}</label>
View ToDoList.cshtml
@page "/"
<input bind="@SearchTerm" />
<span class="text-muted ml-5">
Showing @FilteredToDos.Count out of @ToDoItems.Count
</span>
<h4 class="mt-4">To Do's</h4>
<ul>
@scottsauber
scottsauber / ToDoList.cshtml
Last active Mar 25, 2019
bind-value-oninput example
View ToDoList.cshtml
@page "/"
<input bind-value-oninput="@SearchTerm" />
<span class="text-muted ml-5">
Showing @FilteredToDos.Count out of @ToDoItems.Count
</span>
<h4 class="mt-4">To Do's</h4>
<ul>
View FileController.cs
[HttpPost("Download/{id:guid}")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Download(Guid id)
{
// Retrieve some file from some service
ApplicationFile file = await _fileService.GetFileAsync(id);
string extension = Path.GetExtension(file.NameWithExtension);
string contentType = "";
View FileController.cs
[HttpPost("Download/{id:guid}")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Download(Guid id)
{
// Retrieve some file from some service
ApplicationFile file = await _fileService.GetFileAsync(id);
var fileProvider = new FileExtensionContentTypeProvider();
// Figures out what the content type should be based on the file name.
if (!fileProvider.TryGetContentType(file.NameWithExtension, out string contentType))
View FileController.cs
[Route("File")]
public class FileController : Controller
{
private readonly IFileService _fileService;
public FileController(IFileService fileService)
{
_fileService = fileService;
}
View FileController.cs
[Route("File")]
public class FileController : Controller
{
[HttpPost("Download/{id:guid}")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Download(Guid id)
{
// Grab a test.pdf back one directory. Look ma - it even runs on Linux with Path.DirectorySeparatorChar!
var fileContent = await File.ReadAllBytesAsync($"..{Path.DirectorySeparatorChar}test.pdf");
You can’t perform that action at this time.