Last post Aug 23, 2019 08:03 AM by jiadongm
Aug 14, 2019 08:24 AM|N1ZAM|LINK
I have a create view, now I want to have search functionality but I want to use the same view that I have used for Create. May be the UI will be bit complex... checking if a model is not null on each control and render otherwise render a default controls
without values being populated.
My controller is like this
BindControls();=> Most of them drop downs
Search( FormCollection fc)
int id= Conver.toInt32(fc["id"]);
model = getmolde(id);
ViewBag.Model = getmolde(id);
First approach Model is null and in Second Approach ViewBag is null.
Aug 14, 2019 08:34 AM|DA924|LINK
Aug 16, 2019 01:28 AM|Brando ZWZ|LINK
Could you please tell me what’s the payload sent by the browser ?
Is the payload a form or a string in application/json format ? Could you please press F12 and check the http request ? And it would be great if you show us the related code (including the View file) if possible.
Besides, I don’t think it’s a good idea to use the same view for two different controller actions. If you want to reuse the view files, it’s better to refactor your code and use a partial view.
Aug 21, 2019 11:29 AM|N1ZAM|LINK
May be I am unaware, but could you please highlight on whats wrong using same view for different Action methods, when the view is same? I could only think of a bit complex view... but I am kinda ok with it. Besides I think its too much of a html, creating
single view for each Action method and we should be able to reuse the same view more specifically when the view is same.
Secnario is I have couple of dropdowns and text boxes on a view for Create. User also wants a search functionality on the same page, which makes sence cause it will be our drawback incase user is asked to navigate to a differnt page to search and differnt
page to insert record.
Is the payload a form or a string in application/json format ? No its not. I would not be able to share the code but I could give you a sample... this is a rough draft... dont concentrate on html rather focus on logic. Cant we use
the same view for two different purpose?
<input type="text" id="txtName" name="Name" value="@Model.Name">
<input type="text" id="txtName" name="Name">
Aug 21, 2019 12:19 PM|mgebhard|LINK
I prefer separate INSERT (POST) and UPDATE (PUT) because it follows the standard RESTful patterns.
It seems that you made up your mind and want validation that using the same View to INSERT and UPDATE is the "right" pattern. This is a debatable question and ultimately it is up to you.
Aug 21, 2019 12:34 PM|DA924|LINK
Aug 23, 2019 08:03 AM|jiadongm|LINK
Since you didn’t use the application/json, I suggest you could use partialview, you can make your “search” view as a partialview, then renference it in the “create” view. This also enables you to create and search on the same page.Using different views doesn't
mean you have to jump to different pages to implement the functions, so your worries are redundant.
The disadvantages of using same view for different Action methods:
1. the view becomes more complicated
2. When errors occurs, it's hard to locate errors
3. It does not meet the design principles of SOC