0

I have a view like below.

enter image description here

there is a column named "Durum". I set the record's value to online or offline with this. I change this value on this page. When I click online image, it becomes offline. I make this using ajax like below:

 @foreach(var item in Model) { ........ ........ @if (item.Online == true) {<img id="[email protected]" src="/Areas/Admin/Content/images/icons/online.png" class="cursorpointer" title="Offline yap" onclick="SetOnlineStatus('/Bank/EditStatus',@item.Id)" />} else{<img id="[email protected]" src="/Areas/Admin/Content/images/icons/offline.png" class="cursorpointer" title="Online yap" onclick="SetOnlineStatus('/Bank/EditStatus',@item.Id)" />} } 

I write above code every page. So I want to put this online/offline part to the partial view. I want to put this online/offline state to a partial view. I need to send Id and Online values to partial. I tried to send two parmeter to partial view, but I could not. Can anyone giv me an idea about this issue? thanks.

2 Answers 2

1

In your view:

@Html.Partial("NamePartialView", item) 

In your partial view:

@model YourNameSpace.Item @{ var id = Mode.Online ? Mode.kId : Mode.Id; var idTag = string.Format("img_online_{0}", id); var title = Mode.Online ? "Onffline yap" : "Online yap"; var srcimg = string.Format("/Areas/Admin/Content/images/icons/{0}", Mode.Online ? "online.png" : "offline.png"); } <img id="@idTag" src="@srcimg" class="cursorpointer" title="@title" onclick="SetOnlineStatus('/Bank/EditStatus', @id)" /> 

Edit for comment

@foreach(var item in Model) { Html.Partial("NamePartialView", item); } 
Sign up to request clarification or add additional context in comments.

2 Comments

I made some correction on my question. I want to ask you one thing about taking the "item" from partial. How can I take item on the partial.For example, in one form, item will come from Category model, and item will come from Article model in another form.
I hope understand your question, you send de object item in the second parameter of method Partial in Html helper.
0

Define the model class for your partial view as you have for the main view, set it to the type of your "item" class and call the renderer:

@{ RenderPartial("..partialName...", item); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.