0

I have experience on Web development on Node JS(front and backend). Now I'm moving to latest Microsoft ASP.Net Core(.Net6) MVC. I love the way they are using c# code in Views(.cshtml). But I got into a situation that I could easily resolve by Javascript but not with c#. Below is the screen. I'm able to enter name and click on "Submit" button. It will return me the result grid. But I'm using return View code.

public IActionResult Index(Person p)
{
        string sPersonKeyword = HttpContext.Request.Form["Person_keyword"];
        DBDataGet(sPersonKeyword);
        return View();
}

The code above send back whole page, leading to my old value on search input box disappear. I know that I could change my technology to do MVC with Ajax in the cshtml, which I used to do in my Node JS projects. Is there any way I could do similar "Partial web page rendering" in cshtml views using c# coding. I tried to create and use Partial view, it still refresh the whole page.

return PartialView("_IndexPartial",recipes);

Below is how my screen looks like: Screen design

  • 1
    you would need ajax if you are updating partial part of web page. why you wanted to avoid Ajax? check https://stackoverflow.com/questions/19392212/how-to-use-jquery-or-ajax-to-update-razor-partial-view-in-c-asp-net-for-a-mvc-p also you can search a bit about signalR – Kamran Shahid Aug 21 '22 at 20:09
  • 1
    Thanks @KamranShahid for your input. The reason why I try to avoid Ajax is related to team development. Most of the memebers are not having experience for JavaScript. I try to get minimum effort to get people get adapt to new Microsoft MVC. – Crazy coder Aug 21 '22 at 20:23
  • This may be helpful to you: https://visualstudiomagazine.com/articles/2017/06/01/ajax-without-javascript.aspx, but I think trying to use Ajax is a batter way. – Xiaotian Yang Aug 23 '22 at 05:58

1 Answers1

0

@KamranShahid and @AbyssWatch818 Thanks guys for the answers, in the end I was able to do regular c# MVC for most of the logic. And only that partial grid upgrade with Ajax. I guess that is currently only way. Let's hope Microsoft develop c# style of Ajax soon. Because I struggle a lot during debugging that Ajax part. But c# allow you to debug directly on cshtml file, which was amazing.