🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / C# / MVC C# ile jsonu internete koyma ve kodu

 

1-) C# -  MVC C# ile jsonu internete koyma ve kodu

1-) projeye sağtık->publish->profile->new custom profile->rastgele isim gir->file System->dosya yolunu gir->Release->file publish options->delete all exi...->finish

 

2-)new project->empty->MVC C#oluştur

 

a-)RouteConfig.cs yi şu şekilde düzelt

 

 defaults: new { controller = "json", action = "json1", id = UrlParameter.Optional }

 

b-)Controllere->add new class->jsonController.cs oluştur ve içeriğini

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

using mvcjson.Models;

namespace mvcjson.Controllers

{

    public class jsonController : Controller

    {

        // GET: json

        public ActionResult Index()

        {

            return View();

        }

        [HttpGet]

        public JsonResult json1()

        {

            List<modelcls> nesne = new List<modelcls>() {

                new modelcls {id=1,isim="asd",soyisim="asd" } };

            Console.WriteLine(nesne);

            return Json(nesne, JsonRequestBehavior.AllowGet);

        }

    }

}

c-)Models->add new class->modelcls.cs oluştur ve içeriğini

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

namespace mvcjson.Models

{

    public class modelcls

    {

        public int id { get; set; }

        public string isim { get; set; }

        public string soyisim { get; set; }

    }}

 2021 Ocak 18 Pazartesi
 468