Skip to content

Instantly share code, notes, and snippets.

@model AspNetCoreMVCMongoDBDemo.Models.Customer
@{
Layout = "_Layout";
}
<h4>Delete Customer</h4>
<div class="row">
<div class="col-md-4">
<form asp-action="Delete">
<label class="control-label">Are you sure to delete </label> <input asp-for="CustomerId" class="form-control" readonly />
<div class="form-group">
@model AspNetCoreMVCMongoDBDemo.Models.Customer
@{
ViewData["Title"] = "Create";
}
<h2>Create Customer Details</h2>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
@model IEnumerable<AspNetCoreMVCMongoDBDemo.Models.Customer>
@{
ViewData["Title"] = "Index";
}
<h2>Index</h2>
<p>
<a asp-action="Create">Create New</a>
</p>
<table class="table table-bordered" style="width:600px">
<thead>
public class HomeController : Controller
{
private IMongoDatabase mongoDatabase;
//Generic method to get the mongodb database details
public IMongoDatabase GetMongoDatabase()
{
var mongoClient = new MongoClient("mongodb://localhost:27017");
return mongoClient.GetDatabase("CustomerDB");
}
public class Customer
{
[BsonId]
public ObjectId Id { get; set; }
[BsonElement]
public int CustomerId { get; set; }
[BsonElement]
public string CustomerName { get; set; }
[BsonElement]
public string Address { get; set; }
Install-Package Microsoft.EntityFrameworkCore.Tools -Version 2.0.1
Install-Package MongoDB.Driver -Version 2.5.0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
namespace NetCoreRazorPageApp.Pages.Employee
{
@page "{id:int}"
@model NetCoreRazorPageApp.Pages.Employee.DeletePageModel
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>DeletePage</title>
</head>
<body>
<h4>Delete Employee Record</h4>
@page
@using NetCoreRazorPageApp.Model
@using Microsoft.EntityFrameworkCore;
@inject EmployeeDbContext dbcontext
@functions {
public IEnumerable<NetCoreRazorPageApp.Model.Employee> Employees { get; set; }
public async Task OnGetAsync()
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
namespace NetCoreRazorPageApp.Pages
{