When you add a Edit (link to edit item) button in a list on a view that is not the default view, you'll notice that after clicking on the button and editing the properties, you will not be redirected to the view you were working on. It will redirect you to the default view of the list.
This is because there is not a "Source" querystring in the link of the button. The link on the button is:
http://servername/Test%20Doc%20Lib/Forms/EditForm.aspx?ID=1
but it should be:
http://servername/Test%20Doc%20Lib/Forms/EditForm.aspx?ID=1&Source=http://servername/Test%20Doc%20Lib/TestView.aspx (a Source querystring that holds the url of the view you are working on)
So I took al look at how this button is built. I found out that there is a Field definition for this button, looking like this:
<Field
ID="{503f1caa-358e-4918-9094-4a2cdc4bc034}"
ReadOnly="TRUE"
Type="Computed"
Name="Edit"
Sortable="FALSE"
Filterable="FALSE"
DisplayName="Edit"
ClassInfo="Icon"
AuthoringInfo="(link to edit item)"
SourceID="http://schemas.microsoft.com/sharepoint/v3"
StaticName="Edit"
FromBaseType="TRUE">
<FieldRefs>
<FieldRef Name="IsCheckedoutToLocal"/>
<FieldRef Name="ServerUrl"/>
<FieldRef Name="CheckedOutUserId"/>
</FieldRefs>
<DisplayPattern>
<IfHasRights>
<RightsChoices>
<RightsGroup PermEditListItems="required"/>
</RightsChoices>
<Then>
<HTML>
<![CDATA[<a href="]]>
</HTML>
<URL Cmd="Edit"/>
<HTML>
<![CDATA[" onclick="STSNavigateWithCheckoutAlert(this.href, ']]>
</HTML>
<IfEqual>
<Expr1>
<Field Name="CheckedOutUserId"/>
</Expr1>
<Expr2/>
<Then>
<ScriptQuote NotAddingQuote="TRUE">
<ListProperty Select="ForceCheckout"/>
</ScriptQuote>
</Then>
<Else>
<HTML><![CDATA[0]]></HTML>
</Else>
</IfEqual>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<Field Name="IsCheckedoutToLocal"/>
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<Field Name="ServerUrl"/>
</ScriptQuote><HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<HttpVDir/>
</ScriptQuote>
<HTML><![CDATA[') ;return false;" target="_self">]]></HTML>
<HTML><![CDATA[<img border="0" alt="]]></HTML>
<HTML>Edit Document Properties</HTML>
<HTML><![CDATA[" src="/_layouts/images/RTESRCED.GIF">]]></HTML>
<HTML><![CDATA[</a>]]></HTML>
</Then>
<Else>
<HTML><![CDATA[ ]]></HTML>
</Else>
</IfHasRights>
</DisplayPattern>
</Field>
So basically, what I had to do is copy this Field definition, and make a custom Field definition for the "correct Edit button". After some javascripting, this is my resulting Field defnition:
Now you can add this Field definition in the schema.xml (in the Fields section) of your list definition like this.
<Field
ID="{00C8F32E-9400-4d61-8C6E-373A0E78E62B}"
ReadOnly="TRUE"
Type="Computed"
Name="EditPropertiesWithRedirect"
Sortable="FALSE"
Filterable="FALSE"
DisplayName="Edit Properties"
ClassInfo="Icon"
AuthoringInfo="(link to edit item, with redirect to correct view)"
SourceID="{F326CD4A-69CD-4b61-A3F1-1427543CD745}"
StaticName="EditPropertiesWithRedirect"
FromBaseType="TRUE">
<FieldRefs>
<FieldRef Name="IsCheckedoutToLocal"/>
<FieldRef Name="ServerUrl"/>
<FieldRef Name="CheckedOutUserId"/>
</FieldRefs>
<DisplayPattern>
<IfHasRights>
<RightsChoices>
<RightsGroup PermEditListItems="required"/>
</RightsChoices>
<Then>
<HTML>
<![CDATA[<a href="" ]]>
</HTML>
<HTML>
<![CDATA[" onclick="STSNavigateWithCheckoutAlert(this.href, ']]>
</HTML>
<IfEqual>
<Expr1>
<Field Name="CheckedOutUserId"/>
</Expr1>
<Expr2/>
<Then>
<ScriptQuote NotAddingQuote="TRUE">
<ListProperty Select="ForceCheckout"/>
</ScriptQuote>
</Then>
<Else>
<HTML><![CDATA[0]]></HTML>
</Else>
</IfEqual>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<Field Name="IsCheckedoutToLocal"/>
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<Field Name="ServerUrl"/>
</ScriptQuote>
<HTML><![CDATA[',']]></HTML>
<ScriptQuote NotAddingQuote="TRUE">
<HttpVDir/>
</ScriptQuote>
<HTML>
<![CDATA['); javascript:window.location=']]>
</HTML>
<URL Cmd="Edit"/>
<HTML>
<![CDATA[' + '&Source=' + escape(window.location);]]>
</HTML>
<HTML><![CDATA[return false;" target="_self">]]></HTML>
<HTML><![CDATA[<img border="0" alt="]]></HTML>
<HTML>Edit Document Properties</HTML>
<HTML><![CDATA[" src="/_layouts/images/edititem.gif">]]></HTML>
<HTML><![CDATA[</a>]]></HTML>
</Then>
<Else>
<HTML><![CDATA[ ]]></HTML>
</Else>
</IfHasRights>
</DisplayPattern>
</Field>
The field will appear in the Create View or Modify View page, so you can select it to add the field to your view. Now you'll have an edit button that redirects to the correct view after updating the properties.