Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

public async Task OnPostAsync()

$
0
0

I am working with some generated code, had to modify it for image upload.  And I am more used to something like this:

        public void OnPost()
        {
            string petid = Request.Form["petid"];
            string petname = Request.Form["petname"];
            string odate = Request.Form["odate"].ToString();
            var ocheck = Request.Form["ocheck"].ToString();
            string postvalues = petid + "|" + petname + "|" + odate + "|" + ocheck;
            Lqtest upet = new Lqtest();
            upet.Updatepipe(postvalues);
            ViewData["updated"] = "Record updated";

        }
// just test db and testing with delimited and with json in another model.

And custom model:

        public void Updatepipe(string uplist)
        {

            string[] plist = uplist.Split('|');

            string petid = plist[0];
            string petname = plist[1];
            string odate = plist[2];
            string ocheck = plist[3];


            int vpetid = Convert.ToInt32(petid);

            Dbcon ob = new Dbcon();
            using (var db = ob.OpBuilder())
            {
                var entity = db.Pet.Where(x => x.PetID == vpetid).First();
                entity.PetName = petname;

                entity.Odate = !string.IsNullOrEmpty(odate) ? (DateTime?)DateTime.Parse(odate) : null;

                entity.Ocheck = ocheck == "1" || ocheck == "on" ? true : false;

                db.SaveChanges();
            }

        }

However the generated code starts with:

        public async Task<IActionResult> OnPostAsync()
        {
         ///   more code /////

Inside of the method I cannot use:

string pic = Request.Form["Upload"];  //  does not work
  if (pic == null).....

///  tried

    if (string.IsNullOrEmpty(pic) ......



// however I can use
    if (Upload == null).....

Why doesn't standard Request.Form work in this generated method.

Note I am used to writing my own classes for crud, and new to using and having to modify the generated code.

Thanks


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>