This video demonstrate how to delete record in asp.net mvc.
Tuesday, August 30, 2016
Wednesday, August 24, 2016
6. How To Use AJAX in ASP. NET MVC C# | Jquery | AJAX | ASPHero
Welcome to next tutorial on HOW TO USE AJAX IN ASP.NET MVC. At first open up index.chtml of Views/Home/index.cshtml .We will make a ajax call to retrive a square of supplied number dynamically without reloading the wholwe page. Now write the following code :
@*Welcome to asp.net mvc tutorial about uploading images*@
@*Now we are in Views/Home/index.cshtml*@
@*at first lets include a jquery file for ajax which is already provided by
asp.net mvc as default*@
<script src="~/Scripts/jquery-1.10.2.js"></script>
@*otherwise you can download latest from jquery.com*@
<div style="margin:5px;">
<span>Supply a number to get square of it using AJAX</span>
<br />
<input type="number" id="supplied_number"/>
<br /><br />
<input type="button" value="Show" id="show_button"/>
<br /><br />
<div id="updating_div">Result</div>
</div>
@*lets write our script for ajax call*@
<script>
$(document).ready(function () {
$("#show_button").click(function () {
sNumber = $("#supplied_number").val();
$.ajax({
type:"post",
url: "/Home/square",
data: { number: sNumber },
success: function (data) {
$("#updating_div").html("Result : " + data.result);
}
});
});
});
</script>
@*now lets move to controller action*@
@*Welcome to asp.net mvc tutorial about uploading images*@
@*Now we are in Views/Home/index.cshtml*@
@*at first lets include a jquery file for ajax which is already provided by
asp.net mvc as default*@
<script src="~/Scripts/jquery-1.10.2.js"></script>
@*otherwise you can download latest from jquery.com*@
<div style="margin:5px;">
<span>Supply a number to get square of it using AJAX</span>
<br />
<input type="number" id="supplied_number"/>
<br /><br />
<input type="button" value="Show" id="show_button"/>
<br /><br />
<div id="updating_div">Result</div>
</div>
@*lets write our script for ajax call*@
<script>
$(document).ready(function () {
$("#show_button").click(function () {
sNumber = $("#supplied_number").val();
$.ajax({
type:"post",
url: "/Home/square",
data: { number: sNumber },
success: function (data) {
$("#updating_div").html("Result : " + data.result);
}
});
});
});
</script>
@*now lets move to controller action*@
Now we need to make a function in controller action to return square number in json format.
public ActionResult square(int number) //parameter must be same as supplied
{
int squaredResult = number * number;
return Json(new { result = squaredResult }, JsonRequestBehavior.AllowGet);
//thats it to finish our job :) lets run
}
That's enough to make a ajax call. In return controller action is returning result in json form which is displayed in updating div.Hope you guys learn the concept. Stay tuned for more tutorials, to be more clear you can watch this video too. Thanks :)
Tuesday, August 23, 2016
Multiple Files Upload in ASP.NET MVC C#
You are at correct place to give a good start on ASP.NET MVC. Here i am going to show you how to upload multiple files in asp.net mvc.here we go.
Design code in view:
@*Welcome to asp.net mvc tutorial about uploading images*@
@*Now we are in Views/Home/index.cshtml*@
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<h3>Upload Image</h3>
<input multiple type="file" name="files" value="Browse"/>
<br />
<input type="submit" value="Upload" />
}
@if(ViewBag.UploadSuccess==true)
{
<span>Upload Completed Successfully</span>
}
Controller code in HomeController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ASPtutorial.Models; //your projectName.Models
using System.IO;
namespace ASPtutorial.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost] //must be post method
public ActionResult Index(List<HttpPostedFileBase> files) //take files as a list
{
var path = ""; //for path to save
foreach(var item in files) //iterate in each file
{
if (item != null) //check file is null or not
{
if (item.ContentLength > 0) //check length of bytes are greater then zero or not
{
//for checking uploaded file is image or not
if (Path.GetExtension(item.FileName).ToLower() == ".jpg"
|| Path.GetExtension(item.FileName).ToLower() == ".png"
|| Path.GetExtension(item.FileName).ToLower() == ".gif"
|| Path.GetExtension(item.FileName).ToLower() == ".jpeg")
{
path = Path.Combine(Server.MapPath("~/Content/Images"), item.FileName);
item.SaveAs(path);
ViewBag.UploadSuccess = true;
}
}
}
}
return View();
}
}
}
That's it for multiple file upload , if you wanna see the code in video the watch this,Ok Good luck :)
Design code in view:
@*Welcome to asp.net mvc tutorial about uploading images*@
@*Now we are in Views/Home/index.cshtml*@
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<h3>Upload Image</h3>
<input multiple type="file" name="files" value="Browse"/>
<br />
<input type="submit" value="Upload" />
}
@if(ViewBag.UploadSuccess==true)
{
<span>Upload Completed Successfully</span>
}
Controller code in HomeController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ASPtutorial.Models; //your projectName.Models
using System.IO;
namespace ASPtutorial.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost] //must be post method
public ActionResult Index(List<HttpPostedFileBase> files) //take files as a list
{
var path = ""; //for path to save
foreach(var item in files) //iterate in each file
{
if (item != null) //check file is null or not
{
if (item.ContentLength > 0) //check length of bytes are greater then zero or not
{
//for checking uploaded file is image or not
if (Path.GetExtension(item.FileName).ToLower() == ".jpg"
|| Path.GetExtension(item.FileName).ToLower() == ".png"
|| Path.GetExtension(item.FileName).ToLower() == ".gif"
|| Path.GetExtension(item.FileName).ToLower() == ".jpeg")
{
path = Path.Combine(Server.MapPath("~/Content/Images"), item.FileName);
item.SaveAs(path);
ViewBag.UploadSuccess = true;
}
}
}
}
return View();
}
}
}
That's it for multiple file upload , if you wanna see the code in video the watch this,Ok Good luck :)
Monday, August 22, 2016
4. How To Upload Image In ASP NET MVC
Welcome to tutorial on HOW TO UPLOAD IMAGE IN ASP.NET MVC. Here we go, At first write following line of code in Views/Home/Index.cshtml
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<h3>Upload Image</h3>
<input type="file" name="file" value="Browse"/>
<br />
<input type="submit" value="Upload" />
}
@if(ViewBag.UploadSuccess==true)
{
<span>Upload Completed Successfully</span>
}
Here using statement is used to create a form with help of html helper. Form Submission method is post method. Other type of methods are get,put,delete etc. Important thing to notice while uploading is enctype attribute, here enctype attribute is set to multipart form data. Now use input of type file for uploading file using it. Place a uploading button which actually submits the form to Index actionResult method of Home Controller.
Now in HomeController.cs place the following code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using YourProjectName.Models;
using System.IO; //for file operation
namespace YourProjectName.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
var path = "";
if(file!=null)
{
if(file.ContentLength>0)
{
//for checking uploaded file is image or not
if(Path.GetExtension(file.FileName).ToLower()==".jpg"
|| Path.GetExtension(file.FileName).ToLower() == ".png"
|| Path.GetExtension(file.FileName).ToLower() == ".gif"
|| Path.GetExtension(file.FileName).ToLower() == ".jpeg")
{
path = Path.Combine(Server.MapPath("~/Content/Images"), file.FileName);
file.SaveAs(path);
ViewBag.UploadSuccess = true;
}
}
}
return View();
}
}
}
Here HttppostedFileBase is a datatype to accept the file submitted from the form. At first file is checked it is null or not. If not null that is some file is uploaded then file length is checked if file length is greater then zero then we proceed. Now we check the file extention matches the file format of image or not like jpg,png,gif etc and then if it matches. Now we combine server folder path to upload and the filename together and finally save it with file.saveAs function. ViewBag is used to detect whether image file was successfully uploaded or not. Finally return view to show image is uploded. That's all for uploading image in ASP.NET MVC. Hope you guys understand better, if you have still any doubt then you can watch this video too. Thanks and do subscribe :)
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<h3>Upload Image</h3>
<input type="file" name="file" value="Browse"/>
<br />
<input type="submit" value="Upload" />
}
@if(ViewBag.UploadSuccess==true)
{
<span>Upload Completed Successfully</span>
}
Here using statement is used to create a form with help of html helper. Form Submission method is post method. Other type of methods are get,put,delete etc. Important thing to notice while uploading is enctype attribute, here enctype attribute is set to multipart form data. Now use input of type file for uploading file using it. Place a uploading button which actually submits the form to Index actionResult method of Home Controller.
Now in HomeController.cs place the following code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using YourProjectName.Models;
using System.IO; //for file operation
namespace YourProjectName.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
var path = "";
if(file!=null)
{
if(file.ContentLength>0)
{
//for checking uploaded file is image or not
if(Path.GetExtension(file.FileName).ToLower()==".jpg"
|| Path.GetExtension(file.FileName).ToLower() == ".png"
|| Path.GetExtension(file.FileName).ToLower() == ".gif"
|| Path.GetExtension(file.FileName).ToLower() == ".jpeg")
{
path = Path.Combine(Server.MapPath("~/Content/Images"), file.FileName);
file.SaveAs(path);
ViewBag.UploadSuccess = true;
}
}
}
return View();
}
}
}
Here HttppostedFileBase is a datatype to accept the file submitted from the form. At first file is checked it is null or not. If not null that is some file is uploaded then file length is checked if file length is greater then zero then we proceed. Now we check the file extention matches the file format of image or not like jpg,png,gif etc and then if it matches. Now we combine server folder path to upload and the filename together and finally save it with file.saveAs function. ViewBag is used to detect whether image file was successfully uploaded or not. Finally return view to show image is uploded. That's all for uploading image in ASP.NET MVC. Hope you guys understand better, if you have still any doubt then you can watch this video too. Thanks and do subscribe :)
Sunday, August 21, 2016
Adding Two Numbers In ASP.NET MVC | ASPHero
Welcome to the tutorial on HOW TO ADD TWO NUMBERS IN ASP.NET MVC C#.
You are at absolutely correct page to give a good start.
Now Lets start our job. At first Create a model in Models folder named addmodel.cs.
Add > class . addmodel.cs
// code:
public class addmodel
{
public int firstNum { get; set; } //for first number
public int secondNum { get; set; } //for second number
public int result { get; set; } //for storing result after addition
}
Now we are going to add a actionResult Method in Home Controller
Use a using
//code:
using YourProjectName.Models;
[HttpPost] //this is required for post type of submit
public ActionResult Index(addmodel am) //for this you have to add a using
{
am.result = am.firstNum + am.secondNum;
return View(am); //sending result to view so that we can see it :)
}
Now time to show output in a page.
Write this code in Views/Home/index.cshtml
@*Code: *@
@model YourProjectName.Models.addmodel
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<br />
@Html.EditorFor(m=>m.firstNum)
<br /><br />
@Html.EditorFor(m=>m.secondNum)
<br /><br />
@Html.DisplayFor(m=>m.result)
<br /><br />
<input type="submit" value="Add"/>
}
Now you are ready to go.Just Run The project. If you are still confused then watch this video. And Don't forget to subscribe for more similar kind of stuff. Good luck :)
You are at absolutely correct page to give a good start.
Now Lets start our job. At first Create a model in Models folder named addmodel.cs.
Add > class . addmodel.cs
// code:
public class addmodel
{
public int firstNum { get; set; } //for first number
public int secondNum { get; set; } //for second number
public int result { get; set; } //for storing result after addition
}
Now we are going to add a actionResult Method in Home Controller
Use a using
//code:
using YourProjectName.Models;
[HttpPost] //this is required for post type of submit
public ActionResult Index(addmodel am) //for this you have to add a using
{
am.result = am.firstNum + am.secondNum;
return View(am); //sending result to view so that we can see it :)
}
Now time to show output in a page.
Write this code in Views/Home/index.cshtml
@*Code: *@
@model YourProjectName.Models.addmodel
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<br />
@Html.EditorFor(m=>m.firstNum)
<br /><br />
@Html.EditorFor(m=>m.secondNum)
<br /><br />
@Html.DisplayFor(m=>m.result)
<br /><br />
<input type="submit" value="Add"/>
}
Now you are ready to go.Just Run The project. If you are still confused then watch this video. And Don't forget to subscribe for more similar kind of stuff. Good luck :)
Saturday, August 20, 2016
2. Displaying Images in ASP NET MVC | ASPHero
Welcome to the tutorial on HOW TO DISPLAY IMAGE IN ASP.NET MVC. You are at right place to move ahead.
Sometimes in life we feel difficulties with small things too, if we can't solve that we can't move ahead, similarly this is the thing here, it is also a pretty easy way to do, but at first we all get difficulties, here the solution for displaying images in asp.net mvc.
At first Add a image file in Content folder.
Right click on Content > Add > Existing Item> choose image> OK
HTML Code in file Home/index.cshtml
<img src="@Url.Content("~/Content/imagename.png")" width="500" height="500" />
Its that much easy, Good luck and keep going, I m always with you :)
Further You can watch this video too.
Sometimes in life we feel difficulties with small things too, if we can't solve that we can't move ahead, similarly this is the thing here, it is also a pretty easy way to do, but at first we all get difficulties, here the solution for displaying images in asp.net mvc.
At first Add a image file in Content folder.
Right click on Content > Add > Existing Item> choose image> OK
HTML Code in file Home/index.cshtml
<img src="@Url.Content("~/Content/imagename.png")" width="500" height="500" />
Its that much easy, Good luck and keep going, I m always with you :)
Further You can watch this video too.
Thursday, August 18, 2016
How to make DropDownList in ASP.NET MVC
Welcome to asp.net Tutorial on how to make dropdown list in asp.net mvc. You are at absolutely right place to start. Lets move on to see how to solve it.
We are making dropdownlist in a View. i.e Home/Index.cshtml
At first create a SelectListItem
@{
List<SelectListItem> daysList = new List<SelectListItem>();
daysList.Add(new SelectListItem { Text = "Sunday", Value = "0"});
daysList.Add(new SelectListItem { Text = "Monday", Value = "1" });
daysList.Add(new SelectListItem { Text = "Tuesday", Value = "2"});
daysList.Add(new SelectListItem { Text = "Wednesday", Value = "0" });
daysList.Add(new SelectListItem { Text = "Thursday", Value = "0"});
daysList.Add(new SelectListItem { Text = "Friday", Value = "0"});
daysList.Add(new SelectListItem { Text = "Saturday", Value = "0" });
}
We are making dropdownlist in a View. i.e Home/Index.cshtml
At first create a SelectListItem
@{
List<SelectListItem> daysList = new List<SelectListItem>();
daysList.Add(new SelectListItem { Text = "Sunday", Value = "0"});
daysList.Add(new SelectListItem { Text = "Monday", Value = "1" });
daysList.Add(new SelectListItem { Text = "Tuesday", Value = "2"});
daysList.Add(new SelectListItem { Text = "Wednesday", Value = "0" });
daysList.Add(new SelectListItem { Text = "Thursday", Value = "0"});
daysList.Add(new SelectListItem { Text = "Friday", Value = "0"});
daysList.Add(new SelectListItem { Text = "Saturday", Value = "0" });
}
Here we are creating list of days to display it in dropdown list. If you like to select sunday as default then use this code.
daysList.Add(new SelectListItem { Text = "Sunday", Value = "0",selected=true});
You can give any text or value as you like, whichever you need later. Now Let's create DropDownList in our page.
<h1>Select Day</h1>
@Html.DropDownList("Days", daysList, "Select Day")
This Completes our task on making dropdownlist. If you are still confused then you can watch this video too. Thanks.
Sunday, August 14, 2016
How To Make Money By Just Watching Youtube Videos
Welcome to new tutorial on HOW TO MAKE MONEY BY JUST WTCHING YOUTUBE VIDEOS.
For this you have to go to www.paid2youtube.com. Register there with your name and email. Select your country. If you face money withdrawing problems in your country from paypal then you can choose that country which accepts paypal. After creating account you will get a confirmation email, just open that email and verify your account. Now you are all set to go for earning from paid2youtube. Just open paid2youtube.com , login there with username , password and a captcha given there. After that you will see the list of videos which you can click to view. For security purpose you are asked to chose colours from boxes just choose correct color. And then you will see videos.some are of 1 minutes or some are of 10 seconds, according to that you will generate the revenue and you will start earning instantly, this process may be slow but its a genuine method, making money was never easy. Ok guys best of luck see you later :)
For this you have to go to www.paid2youtube.com. Register there with your name and email. Select your country. If you face money withdrawing problems in your country from paypal then you can choose that country which accepts paypal. After creating account you will get a confirmation email, just open that email and verify your account. Now you are all set to go for earning from paid2youtube. Just open paid2youtube.com , login there with username , password and a captcha given there. After that you will see the list of videos which you can click to view. For security purpose you are asked to chose colours from boxes just choose correct color. And then you will see videos.some are of 1 minutes or some are of 10 seconds, according to that you will generate the revenue and you will start earning instantly, this process may be slow but its a genuine method, making money was never easy. Ok guys best of luck see you later :)
Subscribe to:
Posts (Atom)